﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import Transactions.*;
    import Classes.util.*;
    import GameMode.*;
    import Engine.*;

    public class Road extends Decoration {

        public static const LEFT:int = 0;
        public static const DOWN:int = 1;
        public static const RIGHT:int = 2;
        public static const UP:int = 3;
        public static const DIRECTION_MAX:int = 4;
        public static const OVERLAY_NONE:int = 0;
        public static const OVERLAY_BOTTOM:int = 1;
        public static const OVERLAY_TOP:int = 2;
        public static const OVERLAY_OFFSET:int = 3;
        public static const CAN_ADJUST:int = 1;
        public static const SHOULD_ADJUST:int = 2;
        public static const SIZE_X:Number = 3;
        public static const SIZE_Y:Number = 3;
        protected static const m_flipDirection:Array = [2, 3, 0, 1];

        protected static var m_roadRules:Array;
        protected static var m_roadRules2x3:Array;
        protected static var m_roadRules3x2:Array;
        protected static var m_roadRules4x3:Array;
        protected static var m_roadRules3x4:Array;
        protected static var m_dbgShape:Shape = null;
        public static var m_allowStretchCorners:Boolean = true;
        public static var m_allowTighten:Boolean = true;
        protected static var SPRITE_SCALE:Number = (1 / Global.gameSettings.getNumber("maxZoom", 4));
        protected static var s_shrinkRoad1:Road = null;
        protected static var s_shrinkRoad2:Road = null;
        protected static var s_shrinkDir1:int = -1;
        protected static var s_shrinkDir2:int = -1;
        private static var s_nearX:Number = 0;
        private static var s_nearY:Number = 0;

        protected const ROAD:String = "road";

        protected var m_currentRule:Object = null;
        protected var m_partialRuleMatch:Boolean = false;
        protected var m_overlay1:Sprite = null;
        protected var m_overlay2:Sprite = null;
        protected var m_overlay3:DisplayObject = null;
        protected var m_adjacent:Array = null;
        protected var m_adjacentPartial:Array = null;
        protected var m_adjacentTight:Array = null;
        protected var m_adjacentStretch:Array = null;
        protected var m_adjacentRoads:Array = null;
        protected var m_canAdjust:Array = null;
        protected var m_saveDragItem:Item;
        protected var m_isLeftRight:Boolean = false;
        protected var m_isUpDown:Boolean = false;
        protected var m_isCorner:Boolean = false;
        protected var m_isTightSection:Boolean = false;
        protected var m_tightDirection:int = 0;
        protected var m_isStretchSection:Boolean = false;
        protected var m_stretchDirection:int = 0;
        protected var m_overlayContentMode:int = 0;
        protected var m_overlayContentX:Number = 0;
        protected var m_overlayContentY:Number = 0;
        protected var m_overlay1Mode:int = 0;
        protected var m_overlay1X:Number = 0;
        protected var m_overlay1Y:Number = 0;
        protected var m_overlay2Mode:int = 0;
        protected var m_overlay2X:Number = 0;
        protected var m_overlay2Y:Number = 0;
        protected var m_fitShrink:Boolean = false;
        protected var m_fitStretch:Boolean = false;
        protected var m_fitOffset:Vector2;
        protected var m_isRoadBeingDragged:Boolean = false;
        protected var m_invalidDragPos:Boolean = false;
        protected var m_attached:Boolean = false;
        protected var m_checkForReplaceAtDrop:Boolean = false;
        protected var m_didConnectivity:Boolean = false;

        public function Road(_arg1:String=null){
            var _local2:Object;
            var _local3:Array;
            this.m_fitOffset = new Vector2();
            if (m_roadRules == null){
                m_roadRules = [{
                    match:[LEFT],
                    partial:[LEFT],
                    tile:"road_cap_ne"
                }, {
                    match:[UP],
                    partial:[UP],
                    tile:"road_cap_se"
                }, {
                    match:[RIGHT],
                    partial:[RIGHT],
                    tile:"road_cap_sw"
                }, {
                    match:[DOWN],
                    partial:[DOWN],
                    tile:"road_cap_nw"
                }, {
                    match:[UP, LEFT],
                    partial:[LEFT],
                    corner:[UP],
                    tile:"corner_w",
                    overlay:"straightaway_e",
                    overlay2:"corner_b_w"
                }, {
                    match:[UP, LEFT],
                    partial:[UP],
                    corner:[LEFT],
                    tile:"corner_w",
                    overlay:"straightaway_n",
                    overlay2:"corner_b_w"
                }, {
                    match:[UP, RIGHT],
                    partial:[UP],
                    corner:[RIGHT],
                    tile:"corner_n",
                    overlay:"straightaway_n",
                    overlay2:"corner_b_n"
                }, {
                    match:[UP, RIGHT],
                    partial:[RIGHT],
                    corner:[UP],
                    tile:"corner_n",
                    overlay:"straightaway_e",
                    overlay2:"corner_b_n"
                }, {
                    match:[LEFT, DOWN],
                    partial:[LEFT],
                    corner:[DOWN],
                    tile:"corner_s",
                    overlay:"straightaway_e",
                    overlay2:"corner_b_s"
                }, {
                    match:[LEFT, DOWN],
                    partial:[DOWN],
                    corner:[LEFT],
                    tile:"corner_s",
                    overlay:"straightaway_n",
                    overlay2:"corner_b_s"
                }, {
                    match:[RIGHT, DOWN],
                    partial:[RIGHT],
                    corner:[DOWN],
                    tile:"corner_e",
                    overlay:"straightaway_e",
                    overlay2:"corner_b_e"
                }, {
                    match:[RIGHT, DOWN],
                    partial:[DOWN],
                    corner:[RIGHT],
                    tile:"corner_e",
                    overlay:"straightaway_n",
                    overlay2:"corner_b_e"
                }, {
                    match:[UP, LEFT, RIGHT],
                    partial:[UP],
                    tee:[UP],
                    tile:"straightaway_n",
                    overlay:"tcap_se"
                }, {
                    match:[UP, LEFT, DOWN],
                    partial:[LEFT],
                    tee:[LEFT],
                    tile:"straightaway_e",
                    overlay:"tcap_ne"
                }, {
                    match:[LEFT, RIGHT, DOWN],
                    partial:[DOWN],
                    tee:[DOWN],
                    tile:"straightaway_n",
                    overlay:"tcap_nw"
                }, {
                    match:[UP, RIGHT, DOWN],
                    partial:[RIGHT],
                    tee:[RIGHT],
                    tile:"straightaway_e",
                    overlay:"tcap_sw"
                }, {
                    match:[UP, DOWN, LEFT, RIGHT],
                    partial:[LEFT, RIGHT],
                    cross:[LEFT, RIGHT],
                    tile:"straightaway_e",
                    overlay:"tcap_ne",
                    overlay2:"tcap_sw"
                }, {
                    match:[LEFT, RIGHT, UP, DOWN],
                    partial:[UP, DOWN],
                    cross:[UP, DOWN],
                    tile:"straightaway_n",
                    overlay:"tcap_se",
                    overlay2:"tcap_nw"
                }, {
                    match:[UP, DOWN, LEFT, RIGHT],
                    partial:[LEFT],
                    cross:[LEFT, RIGHT],
                    tile:"straightaway_e",
                    overlay:"tcap_ne",
                    overlay2:"tcap_sw"
                }, {
                    match:[LEFT, RIGHT, UP, DOWN],
                    partial:[UP],
                    cross:[UP, DOWN],
                    tile:"straightaway_n",
                    overlay:"tcap_se",
                    overlay2:"tcap_nw"
                }, {
                    match:[UP, DOWN, LEFT, RIGHT],
                    partial:[RIGHT],
                    cross:[LEFT, RIGHT],
                    tile:"straightaway_e",
                    overlay:"tcap_ne",
                    overlay2:"tcap_sw"
                }, {
                    match:[LEFT, RIGHT, UP, DOWN],
                    partial:[DOWN],
                    cross:[UP, DOWN],
                    tile:"straightaway_n",
                    overlay:"tcap_se",
                    overlay2:"tcap_nw"
                }, {
                    match:[UP, LEFT, RIGHT],
                    partial:[LEFT, RIGHT],
                    tee:[UP],
                    tile:"straightaway_n",
                    overlay:"tcap_se",
                    overlay2:"straightaway_e"
                }, {
                    match:[UP, LEFT, DOWN],
                    partial:[UP, DOWN],
                    tee:[LEFT],
                    tile:"straightaway_e",
                    overlay:"tcap_ne",
                    overlay2:"straightaway_n"
                }, {
                    match:[LEFT, RIGHT, DOWN],
                    partial:[LEFT, RIGHT],
                    tee:[DOWN],
                    tile:"straightaway_n",
                    overlay:"tcap_nw",
                    overlay2:"straightaway_e"
                }, {
                    match:[UP, RIGHT, DOWN],
                    partial:[UP, DOWN],
                    tee:[RIGHT],
                    tile:"straightaway_e",
                    overlay:"tcap_sw",
                    overlay2:"straightaway_n"
                }, {
                    match:[LEFT],
                    tile:"road_cap_ne"
                }, {
                    match:[UP],
                    tile:"road_cap_se"
                }, {
                    match:[RIGHT],
                    tile:"road_cap_sw"
                }, {
                    match:[DOWN],
                    tile:"road_cap_nw"
                }, {
                    match:[UP, LEFT],
                    tile:"corner_w"
                }, {
                    match:[UP, RIGHT],
                    tile:"corner_n"
                }, {
                    match:[LEFT, DOWN],
                    tile:"corner_s"
                }, {
                    match:[RIGHT, DOWN],
                    tile:"corner_e"
                }, {
                    match:[UP, DOWN],
                    tile:"straightaway_e"
                }, {
                    match:[LEFT, RIGHT],
                    tile:"straightaway_n"
                }, {
                    match:[UP, LEFT, RIGHT],
                    tile:"tshape_nw",
                    tee:[UP],
                    overlay:"tcap_se"
                }, {
                    match:[UP, LEFT, DOWN],
                    tile:"tshape_sw",
                    tee:[LEFT],
                    overlay:"tcap_ne"
                }, {
                    match:[LEFT, RIGHT, DOWN],
                    tile:"tshape_se",
                    tee:[DOWN],
                    overlay:"tcap_nw"
                }, {
                    match:[UP, RIGHT, DOWN],
                    tile:"tshape_ne",
                    tee:[RIGHT],
                    overlay:"tcap_sw"
                }, {
                    match:[UP, LEFT, RIGHT, DOWN],
                    tile:"4way"
                }, {
                    match:[],
                    tile:"road_circle"
                }];
                m_roadRules2x3 = [{
                    match:[LEFT],
                    tile:"road_cap_ne"
                }, {
                    match:[RIGHT],
                    tile:"road_cap_sw"
                }, {
                    match:[LEFT],
                    partial:[LEFT],
                    tile:"road_cap_ne"
                }, {
                    match:[RIGHT],
                    partial:[RIGHT],
                    tile:"road_cap_sw"
                }, {
                    match:[LEFT, RIGHT],
                    tile:"straightaway_n"
                }, {
                    match:[UP, LEFT],
                    partial:[UP],
                    corner:[LEFT],
                    tile:"corner_w",
                    overlay:"straightaway_n",
                    overlay2:"corner_b_w"
                }, {
                    match:[UP, RIGHT],
                    partial:[UP],
                    corner:[RIGHT],
                    tile:"corner_n",
                    overlay:"straightaway_n",
                    overlay2:"corner_b_n"
                }, {
                    match:[LEFT, DOWN],
                    partial:[DOWN],
                    corner:[LEFT],
                    tile:"corner_s",
                    overlay:"straightaway_n",
                    overlay2:"corner_b_s"
                }, {
                    match:[RIGHT, DOWN],
                    partial:[DOWN],
                    corner:[RIGHT],
                    tile:"corner_e",
                    overlay:"straightaway_n",
                    overlay2:"corner_b_e"
                }, {
                    match:[LEFT, RIGHT, DOWN],
                    partial:[DOWN],
                    tee:[DOWN],
                    tile:"straightaway_n",
                    overlay:"tcap_nw"
                }, {
                    match:[UP, LEFT, RIGHT],
                    partial:[UP],
                    tee:[UP],
                    tile:"straightaway_n",
                    overlay:"tcap_se"
                }, {
                    match:[UP, LEFT, DOWN],
                    partial:[UP, DOWN],
                    tee:[LEFT],
                    tile:"straight_full_e",
                    overlay:"tcap_ne"
                }, {
                    match:[UP, RIGHT, DOWN],
                    partial:[UP, DOWN],
                    tee:[RIGHT],
                    tile:"straight_full_e",
                    overlay:"tcap_sw"
                }, {
                    match:[LEFT, RIGHT, UP, DOWN],
                    partial:[UP, DOWN],
                    cross:[UP, DOWN],
                    tile:"straightaway_n",
                    overlay:"tcap_se",
                    overlay2:"tcap_nw"
                }, {
                    match:[],
                    tile:"straightBlocked_n"
                }];
                m_roadRules3x2 = [{
                    match:[UP],
                    tile:"road_cap_se"
                }, {
                    match:[DOWN],
                    tile:"road_cap_nw"
                }, {
                    match:[UP],
                    partial:[UP],
                    tile:"road_cap_se"
                }, {
                    match:[DOWN],
                    partial:[DOWN],
                    tile:"road_cap_nw"
                }, {
                    match:[UP, DOWN],
                    tile:"straightaway_e"
                }, {
                    match:[UP, LEFT],
                    partial:[LEFT],
                    corner:[UP],
                    tile:"corner_w",
                    overlay:"straightaway_e",
                    overlay2:"corner_b_w"
                }, {
                    match:[UP, RIGHT],
                    partial:[RIGHT],
                    corner:[UP],
                    tile:"corner_n",
                    overlay:"straightaway_e",
                    overlay2:"corner_b_n"
                }, {
                    match:[LEFT, DOWN],
                    partial:[LEFT],
                    corner:[DOWN],
                    tile:"corner_s",
                    overlay:"straightaway_e",
                    overlay2:"corner_b_s"
                }, {
                    match:[RIGHT, DOWN],
                    partial:[RIGHT],
                    corner:[DOWN],
                    tile:"corner_e",
                    overlay:"straightaway_e",
                    overlay2:"corner_b_e"
                }, {
                    match:[UP, LEFT, DOWN],
                    partial:[LEFT],
                    tee:[LEFT],
                    tile:"straightaway_e",
                    overlay:"tcap_ne"
                }, {
                    match:[UP, RIGHT, DOWN],
                    partial:[RIGHT],
                    tee:[RIGHT],
                    tile:"straightaway_e",
                    overlay:"tcap_sw"
                }, {
                    match:[UP, LEFT, RIGHT],
                    partial:[LEFT, RIGHT],
                    tee:[UP],
                    tile:"straight_full_n",
                    overlay:"tcap_se"
                }, {
                    match:[LEFT, RIGHT, DOWN],
                    partial:[LEFT, RIGHT],
                    tee:[DOWN],
                    tile:"straight_full_n",
                    overlay:"tcap_nw"
                }, {
                    match:[UP, DOWN, LEFT, RIGHT],
                    partial:[LEFT, RIGHT],
                    cross:[LEFT, RIGHT],
                    tile:"straightaway_e",
                    overlay:"tcap_ne",
                    overlay2:"tcap_sw"
                }, {
                    match:[],
                    tile:"straightBlocked_e"
                }];
                m_roadRules4x3 = [{
                    match:[UP, LEFT],
                    partial:[UP],
                    corner:[LEFT],
                    tile:"corner_w",
                    overlay:"straight_1_n",
                    overlay2:"corner_b_w"
                }, {
                    match:[UP, RIGHT],
                    partial:[UP],
                    corner:[RIGHT],
                    tile:"corner_n",
                    overlay:"straight_1_nt",
                    overlay2:"corner_b_n"
                }, {
                    match:[LEFT, DOWN],
                    partial:[DOWN],
                    corner:[LEFT],
                    tile:"corner_s",
                    overlay:"straight_1_n",
                    overlay2:"corner_b_s"
                }, {
                    match:[RIGHT, DOWN],
                    partial:[DOWN],
                    corner:[RIGHT],
                    tile:"corner_e",
                    overlay:"straight_1_nt",
                    overlay2:"corner_b_e"
                }, {
                    match:[UP, LEFT, DOWN],
                    partial:[UP, DOWN],
                    tee:[LEFT],
                    tile:"straightaway_e",
                    overlay:"tcap_ne",
                    overlay2:"straightaway_n"
                }, {
                    match:[UP, RIGHT, DOWN],
                    partial:[UP, DOWN],
                    tee:[RIGHT],
                    tile:"straightaway_e",
                    overlay:"tcap_sw",
                    overlay2:"straightaway_n"
                }, {
                    match:[LEFT, RIGHT, DOWN],
                    partial:[DOWN],
                    tee:[DOWN],
                    tile:"straight_full_n",
                    overlay:"tcap_full_nw"
                }, {
                    match:[UP, LEFT, RIGHT],
                    partial:[UP],
                    tee:[UP],
                    tile:"straight_full_n",
                    overlay:"tcap_full_se"
                }, {
                    match:[LEFT, RIGHT, DOWN],
                    tee:[DOWN],
                    tile:"straight_full_n",
                    overlay:"tcap_full_nw"
                }, {
                    match:[UP, LEFT, RIGHT],
                    tee:[UP],
                    tile:"straight_full_n",
                    overlay:"tcap_full_se"
                }, {
                    match:[LEFT, RIGHT, UP, DOWN],
                    partial:[UP, DOWN],
                    cross:[UP, DOWN],
                    tile:"straight_full_n",
                    overlay:"tcap_full_se",
                    overlay2:"tcap_full_nw"
                }, {
                    match:[LEFT, RIGHT],
                    tile:"straight_full_n"
                }, {
                    match:[UP, LEFT],
                    tile:"straight_full_n"
                }, {
                    match:[],
                    tile:"straightBlocked_n"
                }];
                m_roadRules3x4 = [{
                    match:[UP, LEFT],
                    partial:[LEFT],
                    corner:[UP],
                    tile:"corner_w",
                    overlay:"straight_1_et",
                    overlay2:"corner_b_w"
                }, {
                    match:[UP, RIGHT],
                    partial:[RIGHT],
                    corner:[UP],
                    tile:"corner_n",
                    overlay:"straight_1_et",
                    overlay2:"corner_b_n"
                }, {
                    match:[LEFT, DOWN],
                    partial:[LEFT],
                    corner:[DOWN],
                    tile:"corner_s",
                    overlay:"straight_1_e",
                    overlay2:"corner_b_s"
                }, {
                    match:[RIGHT, DOWN],
                    partial:[RIGHT],
                    corner:[DOWN],
                    tile:"corner_e",
                    overlay:"straight_1_e",
                    overlay2:"corner_b_e"
                }, {
                    match:[UP, LEFT, RIGHT],
                    partial:[LEFT, RIGHT],
                    tee:[UP],
                    tile:"straightaway_n",
                    overlay:"tcap_se",
                    overlay2:"straightaway_e"
                }, {
                    match:[LEFT, RIGHT, DOWN],
                    partial:[LEFT, RIGHT],
                    tee:[DOWN],
                    tile:"straightaway_n",
                    overlay:"tcap_nw",
                    overlay2:"straightaway_e"
                }, {
                    match:[UP, LEFT, DOWN],
                    partial:[LEFT],
                    tee:[LEFT],
                    tile:"straight_full_e",
                    overlay:"tcap_full_ne"
                }, {
                    match:[UP, RIGHT, DOWN],
                    partial:[RIGHT],
                    tee:[RIGHT],
                    tile:"straight_full_e",
                    overlay:"tcap_full_sw"
                }, {
                    match:[UP, LEFT, DOWN],
                    tee:[LEFT],
                    tile:"straight_full_e",
                    overlay:"tcap_full_ne"
                }, {
                    match:[UP, RIGHT, DOWN],
                    tee:[RIGHT],
                    tile:"straight_full_e",
                    overlay:"tcap_full_sw"
                }, {
                    match:[UP, DOWN, LEFT, RIGHT],
                    partial:[LEFT, RIGHT],
                    cross:[LEFT, RIGHT],
                    tile:"straight_full_e",
                    overlay:"tcap_full_ne",
                    overlay2:"tcap_full_sw"
                }, {
                    match:[UP, DOWN],
                    tile:"straight_full_e"
                }, {
                    match:[UP, DOWN],
                    tile:"straight_full_e"
                }, {
                    match:[],
                    tile:"straightBlocked_e"
                }];
                for each (_local2 in m_roadRules) {
                    _local3 = _local2.match;
                    _local3.sort();
                };
                for each (_local2 in m_roadRules2x3) {
                    _local3 = _local2.match;
                    _local3.sort();
                };
                for each (_local2 in m_roadRules3x2) {
                    _local3 = _local2.match;
                    _local3.sort();
                };
                for each (_local2 in m_roadRules4x3) {
                    _local3 = _local2.match;
                    _local3.sort();
                };
                for each (_local2 in m_roadRules3x4) {
                    _local3 = _local2.match;
                    _local3.sort();
                };
            };
            super(_arg1);
            m_objectType = WorldObjectTypes.ROAD;
        }
        public static function get overlay():Boolean{
            return (!((m_dbgShape == null)));
        }
        public static function showOverlay(_arg1:Boolean):void{
            if (_arg1){
                if (m_dbgShape == null){
                    m_dbgShape = new Shape();
                    GlobalEngine.viewport.objectBase.addChild(m_dbgShape);
                };
                m_dbgShape.graphics.clear();
                Global.world.citySim.roadManager.updateAllRoadTiles();
            } else {
                if (m_dbgShape != null){
                    if (m_dbgShape.parent){
                        m_dbgShape.parent.removeChild(m_dbgShape);
                    };
                    m_dbgShape.graphics.clear();
                    m_dbgShape = null;
                };
            };
        }
        protected static function canSwitchToBaseItem(_arg1:Road):Boolean{
            var _local2:Item;
            var _local3:Vector3;
            if (((!((_arg1 == null))) && ((_arg1.m_saveDragItem == null)))){
                _arg1.m_saveDragItem = _arg1.m_item;
                if ((((_arg1.m_size.x < SIZE_X)) || ((_arg1.m_size.y < SIZE_Y)))){
                    _local2 = Global.gameSettings.getItemByName(_arg1.baseRoadName());
                    if (_local2 != null){
                        if (((_arg1.m_isRoadBeingDragged) || (!(Global.world.checkCollision(_arg1.m_position.x, _arg1.m_position.y, (_arg1.m_position.x + SIZE_X), (_arg1.m_position.y + SIZE_Y), [_arg1], null, Constants.WORLDOBJECT_ALL, _arg1))))){
                            _arg1.setItem(_local2);
                            _arg1.updateSize();
                            _arg1.conditionallyReattach(true);
                        } else {
                            if (_arg1.m_size.x < SIZE_X){
                                if (!Global.world.checkCollision((_arg1.m_position.x - 1), _arg1.m_position.y, ((_arg1.m_position.x - 1) + SIZE_X), (_arg1.m_position.y + SIZE_Y), [_arg1], null, Constants.WORLDOBJECT_ALL, _arg1)){
                                    _arg1.setPosition((_arg1.m_position.x - 1), _arg1.m_position.y);
                                    _arg1.setItem(_local2);
                                    _arg1.updateSize();
                                    _arg1.conditionallyReattach(true);
                                };
                            } else {
                                if (!Global.world.checkCollision(_arg1.m_position.x, (_arg1.m_position.y - 1), (_arg1.m_position.x + SIZE_X), ((_arg1.m_position.y - 1) + SIZE_Y), [_arg1], null, Constants.WORLDOBJECT_ALL, _arg1)){
                                    _arg1.setPosition(_arg1.m_position.x, (_arg1.m_position.y - 1));
                                    _arg1.setItem(_local2);
                                    _arg1.updateSize();
                                    _arg1.conditionallyReattach(true);
                                };
                            };
                        };
                    };
                } else {
                    if ((((_arg1.m_size.x > SIZE_X)) || ((_arg1.m_size.y > SIZE_Y)))){
                        _local2 = Global.gameSettings.getItemByName(_arg1.baseRoadName());
                        _local3 = _arg1.getPosition();
                        if (_arg1.m_size.x > SIZE_X){
                            if (((!((_arg1.m_adjacentRoads[RIGHT] == null))) && ((_arg1.m_adjacentRoads[LEFT] == null)))){
                                _local3.x = (_local3.x + 1);
                                _arg1.setPosition(_local3.x, _local3.y);
                            };
                        };
                        if (_arg1.m_size.y > SIZE_Y){
                            if (((!((_arg1.m_adjacentRoads[UP] == null))) && ((_arg1.m_adjacentRoads[DOWN] == null)))){
                                _local3.y = (_local3.y + 1);
                                _arg1.setPosition(_local3.x, _local3.y);
                            };
                        };
                        if (_local2 != null){
                            _arg1.setItem(_local2);
                        };
                    };
                };
                _arg1.updateSize();
                _arg1.m_checkForReplaceAtDrop = true;
                return (!((_arg1.m_saveDragItem == null)));
            };
            return (false);
        }
        private static function nearbyRoads(_arg1:GameObject):Boolean{
            var _local2:Road = (_arg1 as Road);
            if (_local2 == null){
                return (false);
            };
            var _local3:Number = 9;
            var _local4:Number = (s_nearX - _local2.m_position.x);
            var _local5:Number = (s_nearY - _local2.m_position.y);
            if (((_local4 * _local4) + (_local5 * _local5)) < (_local3 * _local3)){
                return (true);
            };
            return (false);
        }

        public function get adjacentRoads():Array{
            return (this.m_adjacentRoads);
        }
        public function get tight():Boolean{
            return (this.m_isTightSection);
        }
        override protected function getLayerName():String{
            return ("road");
        }
        override public function loadObject(_arg1:Object):void{
            super.loadObject(_arg1);
        }
        override public function setHighlighted(_arg1:Boolean, _arg2:uint=16755200):void{
            var _local3:Boolean = ((!(_arg1)) || (Global.world.isEditMode));
            if (_local3){
                super.setHighlighted(_arg1);
            };
        }
        protected function drawDebugInfo():void{
            var _local6:Array;
            if (m_dbgShape == null){
                return;
            };
            var _local1:Number = 0.6;
            m_dbgShape.graphics.lineStyle(1, 4278190335);
            var _local2:Vector3 = getPosition();
            _local2 = getSize().scale(0.5).add(_local2);
            var _local3:Point = IsoMath.tilePosToPixelPos((_local2.x - _local1), (_local2.y - _local1));
            m_dbgShape.graphics.moveTo(_local3.x, _local3.y);
            _local3 = IsoMath.tilePosToPixelPos((_local2.x + _local1), (_local2.y - _local1));
            m_dbgShape.graphics.lineTo(_local3.x, _local3.y);
            _local3 = IsoMath.tilePosToPixelPos((_local2.x + _local1), (_local2.y + _local1));
            m_dbgShape.graphics.lineTo(_local3.x, _local3.y);
            _local3 = IsoMath.tilePosToPixelPos((_local2.x - _local1), (_local2.y + _local1));
            m_dbgShape.graphics.lineTo(_local3.x, _local3.y);
            _local3 = IsoMath.tilePosToPixelPos((_local2.x - _local1), (_local2.y - _local1));
            m_dbgShape.graphics.lineTo(_local3.x, _local3.y);
            var _local4:Box3D = this.getBoundingBox();
            m_dbgShape.graphics.lineStyle(0.25, 2147549183);
            _local3 = IsoMath.tilePosToPixelPos(_local4.x, _local4.y);
            m_dbgShape.graphics.moveTo(_local3.x, _local3.y);
            _local3 = IsoMath.tilePosToPixelPos((_local4.x + _local4.width), _local4.y);
            m_dbgShape.graphics.lineTo(_local3.x, _local3.y);
            _local3 = IsoMath.tilePosToPixelPos((_local4.x + _local4.width), (_local4.y + _local4.height));
            m_dbgShape.graphics.lineTo(_local3.x, _local3.y);
            _local3 = IsoMath.tilePosToPixelPos(_local4.x, (_local4.y + _local4.height));
            m_dbgShape.graphics.lineTo(_local3.x, _local3.y);
            _local3 = IsoMath.tilePosToPixelPos(_local4.x, _local4.y);
            m_dbgShape.graphics.lineTo(_local3.x, _local3.y);
            var _local5:Array = [[-(_local1), 0], [0, -(_local1)], [_local1, 0], [0, _local1]];
            if (((!((this.m_currentRule == null))) && (("partial" in this.m_currentRule)))){
                _local6 = this.m_currentRule.partial;
            } else {
                _local6 = [];
            };
            if (this.m_adjacentRoads == null){
                return;
            };
            var _local7:int;
            while (_local7 < this.m_adjacentRoads.length) {
                if (this.m_adjacentRoads[_local7] == null){
                } else {
                    if (this.m_adjacent.indexOf(_local7) >= 0){
                        m_dbgShape.graphics.lineStyle(1, 4278255360);
                    } else {
                        if (this.m_adjacentPartial.indexOf(_local7) >= 0){
                            m_dbgShape.graphics.lineStyle(1, 4294967040);
                        } else {
                            m_dbgShape.graphics.lineStyle(1, 4294901760);
                        };
                    };
                    _local3 = IsoMath.tilePosToPixelPos((_local2.x + _local5[_local7][0]), (_local2.y + _local5[_local7][1]));
                    m_dbgShape.graphics.moveTo((_local3.x + (2 * _local5[(3 - _local7)][0])), (_local3.y + (2 * _local5[(3 - _local7)][1])));
                    m_dbgShape.graphics.lineTo((_local3.x - (2 * _local5[(3 - _local7)][0])), (_local3.y - (2 * _local5[(3 - _local7)][1])));
                    if (_local6.indexOf(_local7) >= 0){
                        m_dbgShape.graphics.lineStyle(1, 4294902015);
                        m_dbgShape.graphics.moveTo((_local3.x + (2 * _local5[_local7][0])), (_local3.y + (2 * _local5[_local7][1])));
                        m_dbgShape.graphics.lineTo((_local3.x - (2 * _local5[_local7][0])), (_local3.y - (2 * _local5[_local7][1])));
                    };
                };
                _local7++;
            };
        }
        public function getOverlay1():Sprite{
            return (this.m_overlay1);
        }
        public function getOverlay2():Sprite{
            return (this.m_overlay2);
        }
        public function getOverlayImage():String{
            var _local1 = "";
            if (((this.m_currentRule) && (("overlay" in this.m_currentRule)))){
                _local1 = this.m_currentRule.overlay;
            };
            return (_local1);
        }
        public function getOverlayImage2():String{
            var _local1 = "";
            if (((this.m_currentRule) && (("overlay2" in this.m_currentRule)))){
                _local1 = this.m_currentRule.overlay2;
            };
            return (_local1);
        }
        override protected function getCurrentImage():ItemImageInstance{
            var _local1:String = this.getOverlayImage();
            if (_local1 != ""){
                m_item.getCachedImage(_local1);
            };
            _local1 = this.getOverlayImage2();
            if (_local1 != ""){
                m_item.getCachedImage(_local1);
            };
            var _local2 = "road_circle";
            if (!this.m_didConnectivity){
                _local2 = "";
            };
            if (this.m_currentRule){
                _local2 = this.m_currentRule.tile;
            };
            if (this.m_invalidDragPos){
                _local2 = "road_blocked";
            };
            var _local3:ItemImageInstance = m_item.getCachedImage(_local2);
            if ((((((_local3 == null)) && (this.m_didConnectivity))) && (!(m_item.isCachedImageLoading(_local2))))){
                _local3 = m_item.getCachedImage("road_circle");
            };
            return (_local3);
        }
        protected function handleStretchTee(_arg1:ItemImageInstance, _arg2:int, _arg3:ItemImageInstance):void{
            var _local6:Number;
            var _local7:Number;
            var _local8:int;
            var _local9:Road;
            var _local10:Vector2;
            if (_arg1 != null){
                this.m_overlay1Mode = OVERLAY_TOP;
                this.m_overlay1X = 0;
                this.m_overlay1Y = 0;
            };
            var _local4:Boolean;
            var _local5:Boolean;
            if (this.m_adjacentPartial.length == 2){
                _local6 = 0;
                _local7 = 0;
                _arg2 = this.m_adjacentPartial[0];
                _local8 = this.m_adjacent[0];
                _local9 = this.m_adjacentRoads[_arg2];
                if (((_local9) && (this.shouldAdjust(_local9, _arg2)))){
                    if ((((_arg2 == LEFT)) || ((_arg2 == RIGHT)))){
                        _local7 = (_local9.getPositionNoClone().y - getPositionNoClone().y);
                        if (_local8 == UP){
                            _local5 = (_local7 < 0);
                            _local4 = (_local7 > 0);
                        } else {
                            _local5 = (_local7 > 0);
                            _local4 = (_local7 < 0);
                        };
                    } else {
                        _local6 = (_local9.getPositionNoClone().x - getPositionNoClone().x);
                        if (_local8 == RIGHT){
                            _local5 = (_local6 < 0);
                            _local4 = (_local6 > 0);
                        } else {
                            _local5 = (_local6 > 0);
                            _local4 = (_local6 < 0);
                        };
                    };
                    _local10 = IsoMath.getPixelDeltaFromTileDelta(_local6, _local7);
                    this.m_fitOffset.x = _local6;
                    this.m_fitOffset.y = _local7;
                    if (_local4){
                        this.m_fitShrink = true;
                        this.m_overlayContentMode = OVERLAY_OFFSET;
                        this.m_overlayContentX = (_local10.x / SPRITE_SCALE);
                        this.m_overlayContentY = (_local10.y / SPRITE_SCALE);
                        this.m_overlay2Mode = OVERLAY_NONE;
                    } else {
                        if (_local5){
                            this.m_fitStretch = true;
                            this.m_overlayContentMode = OVERLAY_OFFSET;
                            this.m_overlayContentX = (_local10.x / SPRITE_SCALE);
                            this.m_overlayContentY = (_local10.y / SPRITE_SCALE);
                            if (_arg3 != null){
                                this.m_overlay2Mode = OVERLAY_BOTTOM;
                                this.m_overlay2X = 0;
                                this.m_overlay2Y = 0;
                            };
                        };
                    };
                    this.m_overlay1X = (this.m_overlay1X + _local10.x);
                    this.m_overlay1Y = (this.m_overlay1Y + _local10.y);
                };
            };
            if (((!(_local4)) && (!(_local5)))){
                if (m_size.x > SIZE_X){
                    _local10 = IsoMath.getPixelDeltaFromTileDelta(1, 0);
                } else {
                    if (m_size.y > SIZE_Y){
                        _local10 = IsoMath.getPixelDeltaFromTileDelta(0, 1);
                    } else {
                        _arg3 = null;
                    };
                };
                if (_arg3 != null){
                    this.m_overlay2Mode = OVERLAY_BOTTOM;
                    this.m_overlay2X = _local10.x;
                    this.m_overlay2Y = _local10.y;
                };
            };
        }
        protected function handleStretchAdjustment():void{
            this.m_overlayContentMode = Road.OVERLAY_OFFSET;
            var _local1:Number = 0;
            var _local2:Number = 0;
            if (this.m_stretchDirection == DOWN){
                _local2 = -1;
            } else {
                if (this.m_stretchDirection == LEFT){
                    _local1 = -1;
                };
            };
            var _local3:Vector2 = IsoMath.getPixelDeltaFromTileDelta(_local1, _local2);
            this.m_overlayContentX = (_local3.x / SPRITE_SCALE);
            this.m_overlayContentY = (_local3.y / SPRITE_SCALE);
        }
        protected function handleTeeAdjustment(_arg1:ItemImageInstance, _arg2:int, _arg3:int):void{
            var _local7:Number;
            var _local8:Number;
            var _local9:Road;
            var _local10:Boolean;
            var _local11:Vector2;
            var _local4:int = OVERLAY_NONE;
            var _local5:Number = 0;
            var _local6:Number = 0;
            if (_arg1 != null){
                _local4 = OVERLAY_TOP;
                _local7 = 0;
                _local8 = 0;
                _local9 = this.m_adjacentRoads[_arg2];
                if (_local9){
                    _local10 = this.shouldAdjust(_local9, _arg2);
                    if (_local10){
                        if ((((_arg2 == LEFT)) || ((_arg2 == RIGHT)))){
                            _local8 = (_local9.m_position.y - m_position.y);
                            if ((((_local9.m_size.y < SIZE_Y)) && ((_local8 > 0)))){
                                _local8--;
                            };
                        } else {
                            _local7 = (_local9.m_position.x - m_position.x);
                            if ((((_local9.m_size.x < SIZE_X)) && ((_local7 > 0)))){
                                _local7--;
                            };
                        };
                    } else {
                        if ((((_arg2 == LEFT)) || ((_arg2 == RIGHT)))){
                            if ((((m_size.y < SIZE_Y)) && ((_local9.m_size.y >= SIZE_Y)))){
                                if (m_position.y > _local9.m_position.y){
                                    _local8--;
                                };
                            };
                            if ((((m_size.x < SIZE_X)) && ((_local9.m_size.x >= SIZE_X)))){
                                if (m_position.x > _local9.m_position.x){
                                    _local7--;
                                };
                            };
                        };
                    };
                    _local11 = IsoMath.getPixelDeltaFromTileDelta(_local7, _local8);
                    _local5 = (_local5 + _local11.x);
                    _local6 = (_local6 + _local11.y);
                };
            };
            if (_arg3 == 1){
                this.m_overlay1Mode = _local4;
                this.m_overlay1X = _local5;
                this.m_overlay1Y = _local6;
            } else {
                if (_arg3 == 2){
                    this.m_overlay2Mode = _local4;
                    this.m_overlay2X = _local5;
                    this.m_overlay2Y = _local6;
                };
            };
        }
        public function cornerShouldAdjust(_arg1:Road, _arg2:int):Boolean{
            if ((((_arg2 == UP)) || ((_arg2 == DOWN)))){
                if (((!((m_size.x == SIZE_X))) && ((_arg1.m_size.x == SIZE_X)))){
                    return (true);
                };
                if ((((m_size.x == SIZE_X)) && (!((_arg1.m_size.x == SIZE_X))))){
                    return (false);
                };
            } else {
                if (((!((m_size.y == SIZE_Y))) && ((_arg1.m_size.y == SIZE_Y)))){
                    return (true);
                };
                if ((((m_size.y == SIZE_Y)) && (!((_arg1.m_size.y == SIZE_Y))))){
                    return (false);
                };
            };
            var _local3:int = this.m_canAdjust[_arg2];
            var _local4:int;
            if (_arg1.m_canAdjust[Road.m_flipDirection[_arg2]] != null){
                _local4 = _arg1.m_canAdjust[Road.m_flipDirection[_arg2]];
            };
            if ((((_local4 == 0)) && ((_local3 > 0)))){
                return (true);
            };
            if ((((_local3 == 0)) && ((_local4 > 0)))){
                return (false);
            };
            if ((this.m_adjacentPartial.length + this.m_adjacent.length) < (_arg1.m_adjacent.length + _arg1.m_adjacentPartial.length)){
                return (true);
            };
            if ((this.m_adjacentPartial.length + this.m_adjacent.length) > (_arg1.m_adjacent.length + _arg1.m_adjacentPartial.length)){
                return (false);
            };
            return (this.shouldAdjust(_arg1, _arg2));
        }
        public function shouldAdjust(_arg1:Road, _arg2:int):Boolean{
            var _local5:Vector3;
            var _local6:Vector3;
            _arg1 = (_arg1 as Road);
            if (_arg1 == null){
                return (true);
            };
            var _local3:int = this.m_canAdjust[_arg2];
            var _local4:int;
            if (_arg1.m_canAdjust[Road.m_flipDirection[_arg2]] != null){
                _local4 = _arg1.m_canAdjust[Road.m_flipDirection[_arg2]];
            };
            if (_local4 > _local3){
                return (false);
            };
            if (_local4 == _local3){
                _local5 = getPosition();
                _local6 = _arg1.getPosition();
                if (_local5.x < _local6.x){
                    return (false);
                };
                if ((((_local5.x == _local6.x)) && ((_local5.y < _local6.y)))){
                    return (false);
                };
            };
            return (true);
        }
        public function shouldTighten(_arg1:Road, _arg2:int):Boolean{
            var _local3:int = (this.m_adjacent.length + this.m_adjacentPartial.length);
            var _local4:int = (_arg1.m_adjacent.length + _arg1.m_adjacentPartial.length);
            if ((((((((_arg2 == DOWN)) && ((_arg2 == UP)))) && ((_arg1.getSize().y < SIZE_Y)))) && ((getSize().y >= SIZE_Y)))){
                return (false);
            };
            if ((((((((_arg2 == DOWN)) && ((_arg2 == UP)))) && ((_arg1.getSize().y >= SIZE_Y)))) && ((getSize().y < SIZE_Y)))){
                return (true);
            };
            if ((((((((_arg2 == LEFT)) || ((_arg2 == RIGHT)))) && ((_arg1.getSize().x < SIZE_Y)))) && ((getSize().x >= SIZE_X)))){
                return (false);
            };
            if ((((((((_arg2 == LEFT)) || ((_arg2 == RIGHT)))) && ((_arg1.getSize().x >= SIZE_Y)))) && ((getSize().x < SIZE_X)))){
                return (true);
            };
            if ((((_local3 == 2)) && (!((_local4 == 2))))){
                return (true);
            };
            if (((!((_local3 == 2))) && ((_local4 == 2)))){
                return (false);
            };
            if (((this.m_isRoadBeingDragged) && (!(_arg1.m_isRoadBeingDragged)))){
                return (true);
            };
            if (_arg1.m_isRoadBeingDragged){
                return (false);
            };
            var _local5:Vector3 = getPosition();
            var _local6:Vector3 = _arg1.getPosition();
            if (_local5.x < _local6.x){
                return (false);
            };
            if ((((_local5.x == _local6.x)) && ((_local5.y < _local6.y)))){
                return (false);
            };
            return (true);
        }
        public function shouldStretch(_arg1:Road, _arg2:int):Boolean{
            var _local3:int = (this.m_adjacent.length + this.m_adjacentPartial.length);
            var _local4:int = (_arg1.m_adjacent.length + _arg1.m_adjacentPartial.length);
            if ((((((((_arg2 == DOWN)) && ((_arg2 == UP)))) && ((_arg1.getSize().y > SIZE_Y)))) && ((getSize().y <= SIZE_Y)))){
                return (false);
            };
            if ((((((((_arg2 == DOWN)) && ((_arg2 == UP)))) && ((_arg1.getSize().y <= SIZE_Y)))) && ((getSize().y > SIZE_Y)))){
                return (true);
            };
            if ((((((((_arg2 == LEFT)) || ((_arg2 == RIGHT)))) && ((_arg1.getSize().x > SIZE_Y)))) && ((getSize().x <= SIZE_X)))){
                return (false);
            };
            if ((((((((_arg2 == LEFT)) || ((_arg2 == RIGHT)))) && ((_arg1.getSize().x <= SIZE_Y)))) && ((getSize().x > SIZE_X)))){
                return (true);
            };
            if ((((_local3 == 2)) && (!((_local4 == 2))))){
                return (true);
            };
            if (((!((_local3 == 2))) && ((_local4 == 2)))){
                return (false);
            };
            if ((((_local3 == 1)) && ((_local4 > 1)))){
                return (false);
            };
            if ((((_local3 > 1)) && ((_local4 == 1)))){
                return (true);
            };
            if (((this.m_isRoadBeingDragged) && (!(_arg1.m_isRoadBeingDragged)))){
                return (true);
            };
            if (_arg1.m_isRoadBeingDragged){
                return (false);
            };
            var _local5:Vector3 = getPosition();
            var _local6:Vector3 = _arg1.getPosition();
            if (_local5.x < _local6.x){
                return (true);
            };
            if ((((_local5.x == _local6.x)) && ((_local5.y < _local6.y)))){
                return (true);
            };
            return (false);
        }
        protected function checkOverlapCorner():Object{
            var _local2:Number;
            var _local3:Number;
            var _local4:int;
            var _local5:int;
            var _local6:Road;
            var _local7:Vector2;
            var _local8:Boolean;
            var _local9:Boolean;
            var _local10:Vector3;
            var _local11:Vector3;
            var _local12:Array;
            var _local13:Road;
            var _local1 = -1;
            if (this.m_adjacent.length == 1){
                _local1 = this.m_adjacent[0];
            };
            if (this.m_adjacentPartial.length == 1){
                _local2 = 0;
                _local3 = 0;
                _local4 = this.m_adjacentPartial[0];
                _local5 = this.m_adjacent[0];
                _local6 = this.m_adjacentRoads[_local4];
                if (this.m_isTightSection){
                    if (((_local6) && (!((_local6.adjacentRoads[_local1] == null))))){
                        _local8 = (((((_local4 == LEFT)) || ((_local4 == RIGHT)))) && ((_local6.m_size.y >= SIZE_Y)));
                        if ((((((_local4 == UP)) || ((_local4 == DOWN)))) && ((_local6.m_size.x >= SIZE_X)))){
                            _local8 = true;
                        };
                        if (!_local8){
                            this.m_adjacentRoads[_local4] = null;
                            this.m_adjacentPartial = [];
                            return (null);
                        };
                    };
                };
                if (((_local6) && (this.cornerShouldAdjust(_local6, _local4)))){
                    _local9 = false;
                    if ((((_local4 == LEFT)) || ((_local4 == RIGHT)))){
                        _local3 = (_local6.getPosition().y - getPosition().y);
                        if (_local5 == UP){
                            _local9 = (_local3 < 0);
                        } else {
                            _local9 = (_local3 > 0);
                        };
                    } else {
                        _local2 = (_local6.getPosition().x - getPosition().x);
                        if (_local5 == RIGHT){
                            _local9 = (_local2 < 0);
                        } else {
                            _local9 = (_local2 > 0);
                        };
                    };
                    if (_local9){
                        _local10 = getSize();
                        _local11 = getPosition();
                        if (_local2 == 1){
                            _local10.x = (SIZE_X + 1);
                        } else {
                            if (_local2 == -1){
                                _local11.x = (_local11.x - 1);
                                _local10.x = (SIZE_X + 1);
                            } else {
                                if (_local3 == 1){
                                    _local10.y = (SIZE_Y + 1);
                                } else {
                                    if (_local3 == -1){
                                        _local11.y = (_local11.y - 1);
                                        _local10.y = (SIZE_Y + 1);
                                    } else {
                                        return (this.m_currentRule);
                                    };
                                };
                            };
                        };
                        if (Global.world.citySim.waterManager.waterDataLoaded()){
                            if (!Global.world.citySim.waterManager.positionOnValidLand(new Rectangle(_local11.x, _local11.y, _local10.x, _local10.y))){
                                return (null);
                            };
                        };
                        _local12 = [];
                        if (Global.world.checkCollision(_local11.x, _local11.y, (_local11.x + _local10.x), (_local11.y + _local10.y), [this], _local12, Constants.WORLDOBJECT_ALL, this)){
                            if ((((_local12.length == 1)) && ((_local12[0] is Road)))){
                                _local13 = (_local12[0] as Road);
                                if (((_local13.m_isDragged) && (_local13.m_invalidDragPos))){
                                    return (this.m_currentRule);
                                };
                            };
                            this.m_adjacentRoads[_local4] = null;
                            this.m_adjacentPartial = [];
                            return (null);
                        };
                    };
                };
                if (((((_local9) && ((m_size.x <= SIZE_X)))) && ((m_size.y <= SIZE_Y)))){
                    this.m_checkForReplaceAtDrop = true;
                } else {
                    if (((((((!((_local2 == 0))) || (!((_local3 == 0))))) && ((m_size.x >= SIZE_X)))) && ((m_size.y >= SIZE_Y)))){
                        this.m_checkForReplaceAtDrop = true;
                    } else {
                        if (((!((m_size.x == SIZE_X))) || (!((m_size.y == SIZE_Y))))){
                            this.m_checkForReplaceAtDrop = true;
                        };
                    };
                };
            };
            return (this.m_currentRule);
        }
        protected function handleCornerAdjustment(_arg1:ItemImageInstance, _arg2:ItemImageInstance):void{
            var _local5:Number;
            var _local6:Number;
            var _local7:int;
            var _local8:int;
            var _local9:Road;
            var _local10:Vector2;
            var _local3:Boolean;
            var _local4:Boolean;
            if (this.m_adjacentPartial.length == 1){
                _local5 = 0;
                _local6 = 0;
                _local7 = this.m_adjacentPartial[0];
                _local8 = this.m_adjacent[0];
                _local9 = this.m_adjacentRoads[_local7];
                if (((_local9) && (this.cornerShouldAdjust(_local9, _local7)))){
                    if ((((_local7 == LEFT)) || ((_local7 == RIGHT)))){
                        _local6 = (_local9.getPosition().y - getPosition().y);
                        if (_local8 == UP){
                            _local4 = (_local6 < 0);
                            _local3 = (_local6 > 0);
                        } else {
                            _local4 = (_local6 > 0);
                            _local3 = (_local6 < 0);
                        };
                    } else {
                        _local5 = (_local9.getPosition().x - getPosition().x);
                        if (_local8 == RIGHT){
                            _local4 = (_local5 < 0);
                            _local3 = (_local5 > 0);
                        } else {
                            _local4 = (_local5 > 0);
                            _local3 = (_local5 < 0);
                        };
                    };
                    _local10 = IsoMath.getPixelDeltaFromTileDelta(_local5, _local6);
                    this.m_fitOffset.x = _local5;
                    this.m_fitOffset.y = _local6;
                    if (_local3){
                        this.m_fitShrink = true;
                        this.m_overlayContentMode = OVERLAY_OFFSET;
                        this.m_overlayContentX = (_local10.x / SPRITE_SCALE);
                        this.m_overlayContentY = (_local10.y / SPRITE_SCALE);
                        if (_arg2 != null){
                            this.m_overlay2Mode = OVERLAY_TOP;
                            this.m_overlay2X = _local10.x;
                            this.m_overlay2Y = _local10.y;
                        };
                    } else {
                        if (_local4){
                            this.m_fitStretch = true;
                            this.m_overlayContentMode = OVERLAY_OFFSET;
                            this.m_overlayContentX = (_local10.x / SPRITE_SCALE);
                            this.m_overlayContentY = (_local10.y / SPRITE_SCALE);
                            if (_arg1 != null){
                                this.m_overlay1Mode = OVERLAY_BOTTOM;
                                this.m_overlay1X = 0;
                                this.m_overlay1Y = 0;
                            };
                        };
                    };
                };
            };
            if (((!(_local3)) && (!(_local4)))){
                if (m_size.x > SIZE_X){
                    _local10 = IsoMath.getPixelDeltaFromTileDelta(1, 0);
                    if (_arg1 != null){
                        this.m_overlay1Mode = OVERLAY_BOTTOM;
                        this.m_overlay1X = _local10.x;
                        this.m_overlay1Y = _local10.y;
                    };
                } else {
                    if (m_size.y > SIZE_Y){
                        _local10 = IsoMath.getPixelDeltaFromTileDelta(0, 1);
                        if (_arg1 != null){
                            this.m_overlay1Mode = OVERLAY_BOTTOM;
                            this.m_overlay1X = _local10.x;
                            this.m_overlay1Y = _local10.y;
                        };
                    };
                };
            };
        }
        protected function clearContent():void{
            if (((!((this.m_overlay1 == null))) && (!((this.m_overlay1.parent == null))))){
                this.m_overlay1.parent.removeChild(this.m_overlay1);
            };
            if (((!((this.m_overlay2 == null))) && (!((this.m_overlay2.parent == null))))){
                this.m_overlay2.parent.removeChild(this.m_overlay2);
            };
            if (((!((this.m_overlay3 == null))) && (!((this.m_overlay3.parent == null))))){
                this.m_overlay3.parent.removeChild(this.m_overlay3);
            };
            this.m_overlay1 = null;
            this.m_overlay2 = null;
            this.m_overlay3 = null;
        }
        override public function updateDisplayObjectTransform():void{
            super.updateDisplayObjectTransform();
            m_displayObject.y = (Math.floor((m_displayObject.y * 2)) / 2);
        }
        override public function replaceContent(_arg1:DisplayObject):void{
            var _local7:DisplayObject;
            var _local8:DisplayObject;
            var _local9:ItemImageInstance;
            super.replaceContent(_arg1);
            if (!this.m_attached){
                return;
            };
            var _local2:Sprite = (m_displayObject as Sprite);
            var _local3:RoadLayer = (Global.world.getObjectLayerByName(this.getLayerName()) as RoadLayer);
            var _local4:Sprite = _local3.bottomObject;
            var _local5:Sprite = _local3.topObject;
            this.clearContent();
            if (this.m_overlayContentMode == OVERLAY_BOTTOM){
                _arg1.x = (_arg1.x + this.m_overlayContentX);
                _arg1.y = (_arg1.y + this.m_overlayContentY);
            } else {
                if (this.m_overlayContentMode == OVERLAY_TOP){
                    _arg1.x = (_arg1.x + this.m_overlayContentX);
                    _arg1.y = (_arg1.y + this.m_overlayContentY);
                } else {
                    if (this.m_overlayContentMode == OVERLAY_OFFSET){
                        _arg1.x = (_arg1.x + this.m_overlayContentX);
                        _arg1.y = (_arg1.y + this.m_overlayContentY);
                    };
                };
            };
            var _local6:ItemImageInstance = m_item.getCachedImage(this.getOverlayImage());
            if (_local6 != null){
                _local7 = (_local6.image as DisplayObject);
                _local8 = null;
                _local9 = m_item.getCachedImage(this.getOverlayImage2());
                if (_local9 != null){
                    _local8 = (_local9.image as DisplayObject);
                };
                if (((!((this.m_overlay1Mode == OVERLAY_NONE))) && (_local7))){
                    this.m_overlay1 = new Sprite();
                    this.m_overlay1.x = (this.m_overlay1X + _local2.x);
                    this.m_overlay1.y = (this.m_overlay1Y + _local2.y);
                    this.m_overlay1.scaleX = SPRITE_SCALE;
                    this.m_overlay1.scaleY = SPRITE_SCALE;
                    _local7.x = _local6.offsetX;
                    _local7.y = _local6.offsetY;
                    this.m_overlay1.addChild(_local7);
                    if (this.m_overlay1Mode == OVERLAY_TOP){
                        _local5.addChild(this.m_overlay1);
                    } else {
                        if (this.m_overlay1Mode == OVERLAY_BOTTOM){
                            _local4.addChild(this.m_overlay1);
                        };
                    };
                };
                if (((!((this.m_overlay2Mode == OVERLAY_NONE))) && (_local8))){
                    this.m_overlay2 = new Sprite();
                    this.m_overlay2.x = (this.m_overlay2X + _local2.x);
                    this.m_overlay2.y = (this.m_overlay2Y + _local2.y);
                    this.m_overlay2.scaleX = SPRITE_SCALE;
                    this.m_overlay2.scaleY = SPRITE_SCALE;
                    _local8.x = _local9.offsetX;
                    _local8.y = _local9.offsetY;
                    this.m_overlay2.addChild(_local8);
                    if (this.m_overlay2Mode == OVERLAY_TOP){
                        _local5.addChild(this.m_overlay2);
                    } else {
                        if (this.m_overlay2Mode == OVERLAY_BOTTOM){
                            _local4.addChild(this.m_overlay2);
                        };
                    };
                };
            };
            this.drawDebugInfo();
        }
        override protected function adjustSize(_arg1:Vector3):void{
            _arg1.x = (_arg1.y = 3);
        }
        override protected function onItemImageLoaded(_arg1:Event):void{
            this.calculateOverlayOffsets();
            super.onItemImageLoaded(_arg1);
        }
        override public function getDepthPriority():Number{
            if (((this.m_currentRule) && (("tee" in this.m_currentRule)))){
                return (1);
            };
            if ((((this.m_overlayContentMode == OVERLAY_TOP)) || ((this.m_overlayContentMode == OVERLAY_BOTTOM)))){
                return (1);
            };
            return (0);
        }
        override protected function calculateDepthIndex():void{
            super.calculateDepthIndex();
            if (((((((this.m_currentRule) && (("tee" in this.m_currentRule)))) && ((this.m_adjacent.length == 1)))) && ((this.m_adjacentPartial.length == 2)))){
                if ((((((m_size.y < SIZE_Y)) && ((this.m_adjacent[0] == DOWN)))) || ((((m_size.x < SIZE_X)) && ((this.m_adjacent[0] == LEFT)))))){
                    this.m_overlayContentMode = OVERLAY_TOP;
                };
            };
            if (this.m_overlayContentMode == OVERLAY_TOP){
                m_depthIndex = (m_depthIndex - 6000);
            } else {
                if (this.m_overlayContentMode == OVERLAY_BOTTOM){
                    m_depthIndex = (m_depthIndex + 16000);
                };
            };
        }
        protected function calculateOverlayOffsets():void{
            var _local2:ItemImageInstance;
            var _local3:int;
            this.m_overlayContentMode = OVERLAY_NONE;
            this.m_overlay1Mode = OVERLAY_NONE;
            this.m_overlay2Mode = OVERLAY_NONE;
            var _local1:ItemImageInstance = m_item.getCachedImage(this.getOverlayImage());
            if (this.m_isStretchSection){
                this.handleStretchAdjustment();
            };
            if (this.m_isRoadBeingDragged){
                if (((!((Road.s_shrinkRoad1 == null))) && (!((Road.s_shrinkRoad2 == null))))){
                    this.m_overlayContentMode = OVERLAY_BOTTOM;
                } else {
                    if (this.m_invalidDragPos){
                        this.m_overlayContentMode = OVERLAY_TOP;
                    };
                };
                this.m_overlayContentX = 0;
                this.m_overlayContentY = 0;
            };
            if ((((_local1 == null)) && ((this.getOverlayImage() == "")))){
                return;
            };
            if (("tee" in this.m_currentRule)){
                _local3 = this.m_currentRule.tee[0];
                if ((((this.m_adjacentPartial.length == 2)) && ((this.m_adjacent.length == 1)))){
                    _local2 = m_item.getCachedImage(this.getOverlayImage2());
                    this.handleStretchTee(_local1, _local3, _local2);
                    return;
                };
                this.handleTeeAdjustment(_local1, _local3, 1);
            } else {
                if (("cross" in this.m_currentRule)){
                    _local3 = this.m_currentRule.cross[0];
                    this.handleTeeAdjustment(_local1, _local3, 1);
                    _local3 = this.m_currentRule.cross[1];
                    _local1 = m_item.getCachedImage(this.getOverlayImage2());
                    if (_local1 != null){
                        this.handleTeeAdjustment(_local1, _local3, 2);
                    };
                } else {
                    if (("corner" in this.m_currentRule)){
                        _local2 = m_item.getCachedImage(this.getOverlayImage2());
                        this.handleCornerAdjustment(_local1, _local2);
                    };
                };
            };
        }
        public function clearAdjacent():void{
            if (((!((this.m_adjacent == null))) && (m_dbgShape))){
                m_dbgShape.graphics.clear();
            };
            this.m_adjacent = null;
            this.m_adjacentPartial = null;
            this.m_adjacentTight = null;
            this.m_adjacentStretch = null;
            this.m_adjacentRoads = null;
            this.m_currentRule = null;
            this.m_fitOffset.x = 0;
            this.m_fitOffset.y = 0;
            this.m_fitStretch = false;
            this.m_fitShrink = false;
            this.m_isTightSection = false;
        }
        protected function initalUpdateAdjacentCalculations():void{
            var _local7:int;
            var _local9:Road;
            var _local10:Boolean;
            this.m_adjacent = [];
            this.m_adjacentPartial = [];
            this.m_adjacentTight = [];
            this.m_adjacentRoads = [];
            this.m_adjacentStretch = [];
            this.m_canAdjust = [];
            if (this.m_invalidDragPos){
                return;
            };
            var _local1:Number = getPosition().x;
            var _local2:Number = getPosition().y;
            var _local3:Array = [[(_local1 - SIZE_X), _local2], [_local1, (_local2 - SIZE_Y)], [(_local1 + SIZE_X), _local2], [_local1, (_local2 + SIZE_Y)]];
            var _local4:Array = [[((_local1 - SIZE_X) - 1), _local2], [_local1, ((_local2 - SIZE_Y) - 1)], [((_local1 + SIZE_X) + 1), _local2], [_local1, ((_local2 + SIZE_Y) + 1)]];
            var _local5:Array = [[(_local1 - (SIZE_X - 1)), _local2], [_local1, (_local2 - (SIZE_Y - 1))], [(_local1 + (SIZE_X - 1)), _local2], [_local1, (_local2 + (SIZE_Y - 1))]];
            var _local6:Array = [];
            var _local8:int;
            for (;_local8 < _local3.length;_local8++) {
                _local9 = this.isRoadTile(_local3[_local8][0], _local3[_local8][1], _local8);
                if (_local9 != null){
                    if ((((((_local8 == UP)) && ((this.m_size.y < SIZE_Y)))) || ((((_local8 == RIGHT)) && ((this.m_size.x < SIZE_X)))))){
                        continue;
                    };
                    this.m_adjacent.push(_local8);
                    this.m_adjacentRoads[_local8] = _local9;
                } else {
                    _local9 = this.isPartialMatchRoadTile(_local1, _local2, _local3[_local8][0], _local3[_local8][1], _local8);
                    if (_local9){
                        if ((((m_size.x > SIZE_X)) && ((((_local8 == DOWN)) || ((_local8 == UP)))))){
                            if (_local9.m_position.x < m_position.x){
                                continue;
                            };
                        };
                        if ((((m_size.y > SIZE_Y)) && ((((_local8 == LEFT)) || ((_local8 == RIGHT)))))){
                            if (_local9.m_position.y < m_position.y){
                                continue;
                            };
                        };
                        this.m_adjacentPartial.push(_local8);
                        this.m_adjacentRoads[_local8] = _local9;
                    } else {
                        if (Road.m_allowTighten){
                            _local9 = this.isTightMatchRoadTile(_local1, _local2, _local5[_local8][0], _local5[_local8][1], _local8);
                            if (_local9){
                                if ((((((_local8 == DOWN)) && ((_local9.m_size.y < SIZE_Y)))) || ((((_local8 == LEFT)) && ((_local9.m_size.x < SIZE_X)))))){
                                    if ((((((((_local8 == DOWN)) && ((_local9.m_position.x == m_position.x)))) && ((_local9.m_size.x == m_size.x)))) || ((((((_local8 == LEFT)) && ((_local9.m_position.y == m_position.y)))) && ((_local9.m_size.y == m_size.y)))))){
                                        this.m_adjacent.push(_local8);
                                    } else {
                                        this.m_adjacentPartial.push(_local8);
                                    };
                                    this.m_adjacentRoads[_local8] = _local9;
                                } else {
                                    this.m_adjacentTight.push(_local8);
                                    this.m_adjacentRoads[_local8] = _local9;
                                };
                            } else {
                                _local10 = false;
                                if ((((((_local7 == LEFT)) || ((_local7 == RIGHT)))) && (!((m_size.y == SIZE_Y))))){
                                    _local10 = true;
                                };
                                if ((((((_local7 == UP)) || ((_local7 == DOWN)))) && (!((m_size.x == SIZE_X))))){
                                    _local10 = false;
                                };
                                _local9 = this.isStretchMatchRoadTile(_local1, _local2, _local4[_local8][0], _local4[_local8][1], _local8);
                                if (_local9){
                                    if ((((((_local8 == DOWN)) && ((_local9.m_size.y > SIZE_Y)))) || ((((_local8 == LEFT)) && ((_local9.m_size.x > SIZE_X)))))){
                                        if ((((((_local8 == DOWN)) && ((_local9.m_position.x == m_position.x)))) || ((((_local8 == LEFT)) && ((_local9.m_position.y == m_position.y)))))){
                                            if (_local10){
                                                this.m_adjacentPartial.push(_local8);
                                            } else {
                                                this.m_adjacent.push(_local8);
                                            };
                                        } else {
                                            this.m_adjacentPartial.push(_local8);
                                        };
                                        this.m_adjacentRoads[_local8] = _local9;
                                    } else {
                                        if (!_local10){
                                            this.m_adjacentStretch.push(_local8);
                                            this.m_adjacentRoads[_local8] = _local9;
                                        };
                                    };
                                };
                            };
                        };
                    };
                };
            };
        }
        protected function updateAdjacent():void{
            var _local4:int;
            var _local5:Road;
            var _local6:Road;
            var _local7:Vector3;
            var _local8:Vector3;
            var _local9:int;
            var _local10:int;
            var _local11:int;
            var _local12:int;
            if (this.m_adjacentRoads != null){
                return;
            };
            this.initalUpdateAdjacentCalculations();
            if (this.m_adjacentTight.lenght > 1){
                for each (_local4 in this.m_adjacentTight) {
                    this.m_adjacentRoads[_local4] = null;
                };
                this.m_adjacentTight = [];
            };
            this.m_isLeftRight = false;
            this.m_isUpDown = false;
            this.m_isCorner = false;
            var _local1:Array = this.m_adjacent.concat(this.m_adjacentPartial);
            if (this.m_adjacent.length == 2){
                if ((((this.m_adjacent.indexOf(LEFT) >= 0)) && ((this.m_adjacent.indexOf(RIGHT) >= 0)))){
                    this.m_isLeftRight = true;
                };
                if ((((this.m_adjacent.indexOf(UP) >= 0)) && ((this.m_adjacent.indexOf(DOWN) >= 0)))){
                    this.m_isUpDown = true;
                };
            };
            var _local2:Array = this.m_adjacent.concat(this.m_adjacentTight.concat(this.m_adjacentPartial.concat(this.m_adjacentStretch)));
            this.m_isTightSection = false;
            if (_local2.length == 2){
                if ((((_local2.indexOf(LEFT) >= 0)) && ((_local2.indexOf(RIGHT) >= 0)))){
                    this.m_isLeftRight = true;
                };
                if ((((_local2.indexOf(UP) >= 0)) && ((_local2.indexOf(DOWN) >= 0)))){
                    this.m_isUpDown = true;
                };
            };
            if (((this.m_adjacentTight.length) && (((this.m_isLeftRight) || (this.m_isUpDown))))){
                this.m_isTightSection = true;
                this.m_tightDirection = this.m_adjacentTight[0];
            };
            var _local3:Boolean;
            if (((((this.m_adjacent.length + this.m_adjacentTight.length) == 1)) && ((this.m_adjacentPartial.length == 2)))){
                _local5 = this.m_adjacentRoads[this.m_adjacentPartial[0]];
                _local6 = this.m_adjacentRoads[this.m_adjacentPartial[1]];
                _local7 = _local5.getPosition();
                _local8 = _local6.getPosition();
                if (((!((_local7.x == _local8.x))) && (!((_local7.y == _local8.y))))){
                    _local3 = true;
                };
            };
            if (_local3){
                _local9 = 0;
                _local10 = 0;
                _local11 = this.m_adjacentPartial[0];
                _local12 = this.m_adjacentPartial[1];
                _local5 = this.m_adjacentRoads[_local11];
                _local6 = this.m_adjacentRoads[_local12];
                _local7 = _local5.getPosition();
                _local8 = _local6.getPosition();
                if ((((((_local11 == UP)) && ((_local12 == DOWN)))) || ((((_local12 == UP)) && ((_local11 == DOWN)))))){
                    if (_local7.x == m_position.x){
                        _local9 = (_local9 + 2);
                    };
                    if ((_local7.x + _local5.m_size.x) == (m_position.x + m_size.x)){
                        _local9++;
                    };
                    if (_local8.x == m_position.x){
                        _local10 = (_local10 + 2);
                    };
                    if ((_local8.x + _local6.m_size.x) == (m_position.x + m_size.x)){
                        _local10++;
                    };
                } else {
                    if ((((((_local11 == LEFT)) && ((_local12 == RIGHT)))) || ((((_local12 == LEFT)) && ((_local11 == RIGHT)))))){
                        if (_local7.y == m_position.y){
                            _local9 = (_local9 + 2);
                        };
                        if ((_local7.y + _local5.m_size.y) == (m_position.y + m_size.y)){
                            _local9++;
                        };
                        if (_local8.y == m_position.y){
                            _local10 = (_local10 + 2);
                        };
                        if ((_local8.y + _local6.m_size.y) == (m_position.y + m_size.y)){
                            _local10++;
                        };
                    };
                };
                if (_local10 < _local9){
                    this.m_adjacentRoads[_local12] = null;
                    this.m_adjacentPartial.splice(1, 1);
                };
                if (_local9 < _local10){
                    this.m_adjacentRoads[_local11] = null;
                    this.m_adjacentPartial.splice(0, 1);
                };
            };
        }
        protected function getRules():Array{
            if (m_size.x < SIZE_X){
                return (m_roadRules2x3);
            };
            if (m_size.y < SIZE_Y){
                return (m_roadRules3x2);
            };
            if (m_size.x > SIZE_X){
                return (m_roadRules4x3);
            };
            if (m_size.y > SIZE_Y){
                return (m_roadRules3x4);
            };
            if (this.m_isStretchSection){
                if ((((this.m_stretchDirection == UP)) || ((this.m_stretchDirection == DOWN)))){
                    return (m_roadRules3x4);
                };
                return (m_roadRules4x3);
            };
            return (m_roadRules);
        }
        protected function matchPartialRule(_arg1:Array):Object{
            var _local5:Object;
            var _local6:Boolean;
            var _local7:int;
            var _local8:int;
            var _local9:int;
            var _local10:Road;
            var _local11:int;
            var _local12:int;
            var _local2:Boolean;
            var _local3:Array = this.getRules();
            var _local4:int;
            while (_local4 < _local3.length) {
                _local5 = _local3[_local4];
                _local6 = ("partial" in _local5);
                if (!_local6){
                } else {
                    if (_arg1.length == 3){
                        //unresolved if
                    } else {
                        if (_local5.match.length == _arg1.length){
                            _local2 = true;
                            if (((!(Road.m_allowStretchCorners)) && ((_local5.match.length == 2)))){
                            } else {
                                _local7 = 0;
                                _local8 = 0;
                                while (_local8 < _local5.match.length) {
                                    _local9 = _arg1[_local8];
                                    if (_local5.match[_local8] != _local9){
                                        _local2 = false;
                                        break;
                                    };
                                    if (this.m_adjacent.indexOf(_local9) < 0){
                                        if (_local5.partial.indexOf(_local9) < 0){
                                            _local2 = false;
                                            break;
                                        };
                                        _local7 = _local9;
                                    };
                                    _local8++;
                                };
                                if (((_local2) && (!(this.m_isCorner)))){
                                    _local10 = (this.m_adjacentRoads[_local7] as Road);
                                    if (((!((_local10 == null))) && (!(_local10.m_isCorner)))){
                                        _local2 = false;
                                    };
                                };
                                if (_local2){
                                    _local11 = CAN_ADJUST;
                                    if (!this.m_isCorner){
                                        _local11 = 0;
                                    };
                                    if (_arg1.length > 2){
                                        _local11 = SHOULD_ADJUST;
                                    };
                                    for each (_local12 in this.m_adjacentPartial) {
                                        this.m_canAdjust[_local12] = _local11;
                                    };
                                    return (_local5);
                                };
                            };
                        };
                    };
                };
                _local4++;
            };
            return (null);
        }
        protected function matchFullRule(_arg1:Array):Object{
            var _local4:Object;
            var _local5:Boolean;
            var _local6:Boolean;
            var _local7:int;
            var _local2:Array = this.getRules();
            var _local3:int;
            while (_local3 < _local2.length) {
                _local4 = _local2[_local3];
                _local5 = ("partial" in _local4);
                if (_local5){
                } else {
                    if (_local4.match.length == _arg1.length){
                        _local6 = true;
                        _local7 = 0;
                        while (_local7 < _local4.match.length) {
                            if (_local4.match[_local7] != _arg1[_local7]){
                                _local6 = false;
                                break;
                            };
                            _local7++;
                        };
                        if (_local6){
                            return (_local4);
                        };
                    };
                };
                _local3++;
            };
            return (null);
        }
        protected function convertPartialsToAdjacent():void{
            var _local2:int;
            var _local3:Road;
            var _local4:Boolean;
            var _local1:int;
            for (;_local1 < this.m_adjacentPartial.length;_local1++) {
                _local2 = this.m_adjacentPartial[_local1];
                _local3 = this.m_adjacentRoads[_local2];
                _local4 = false;
                switch (_local2){
                    case UP:
                    case DOWN:
                        if (m_size.x != SIZE_X){
                            continue;
                        };
                        _local4 = _local3.m_isLeftRight;
                        break;
                    case LEFT:
                    case RIGHT:
                        if (m_size.y != SIZE_Y){
                            continue;
                        };
                        _local4 = _local3.m_isUpDown;
                        break;
                };
                if (((_local3.m_isCorner) && ((_local3.m_adjacentPartial.length == 1)))){
                    _local4 = true;
                };
                if (((((_local3.m_isCorner) && (_local3.m_currentRule))) && (("tee" in _local3.m_currentRule)))){
                    _local4 = true;
                };
                if (_local4){
                    this.m_adjacent.push(_local2);
                    this.m_adjacent = this.m_adjacent.sort();
                    this.m_adjacentPartial.splice(_local1, 1);
                    _local1--;
                };
            };
        }
        protected function permitTight(_arg1:int, _arg2:Road):Boolean{
            var _local3:Boolean;
            var _local4:Boolean;
            var _local5:Boolean;
            var _local6:Boolean;
            if ((((_arg1 == UP)) && ((m_size.y < SIZE_Y)))){
                return (true);
            };
            if ((((_arg1 == RIGHT)) && ((m_size.x < SIZE_X)))){
                return (true);
            };
            if (this.m_adjacentTight.length != 1){
            };
            return (true);
        }
        protected function convertTightToAdjacent():void{
            var _local2:int;
            var _local3:Road;
            var _local4:int;
            var _local5:Boolean;
            var _local6:Boolean;
            this.m_isTightSection = false;
            var _local1:int;
            for each (_local2 in this.m_adjacentTight) {
                _local3 = this.m_adjacentRoads[_local2];
                _local4 = Road.m_flipDirection[_local2];
                _local5 = (this.m_adjacentTight.indexOf(_local4) >= 0);
                _local5 = false;
                if (((!(_local5)) && (((this.permitTight(_local2, _local3)) || (_local3.permitTight(_local4, this)))))){
                    _local6 = false;
                    switch (_local2){
                        case UP:
                        case DOWN:
                            _local6 = !((_local3.getPosition().x == getPosition().x));
                            break;
                        case LEFT:
                        case RIGHT:
                            _local6 = !((_local3.getPosition().y == getPosition().y));
                            break;
                    };
                    if (_local6){
                        this.m_adjacentPartial.push(_local2);
                        this.m_adjacentPartial = this.m_adjacentPartial.sort();
                    } else {
                        this.m_adjacent.push(_local2);
                        this.m_adjacent = this.m_adjacent.sort();
                    };
                    _local1++;
                    this.m_tightDirection = _local2;
                } else {
                    this.m_adjacentRoads[_local2] = null;
                };
            };
            this.m_isTightSection = (_local1 == 1);
            if ((this.m_adjacentPartial.length + this.m_adjacent.length) > 2){
                this.m_isCorner = true;
            };
        }
        protected function permitStretch(_arg1:int, _arg2:Road):Boolean{
            var _local3:Boolean;
            var _local4:Boolean;
            var _local5:Boolean;
            var _local6:Boolean;
            if ((((_arg1 == UP)) && ((m_size.y > SIZE_Y)))){
                return (true);
            };
            if ((((_arg1 == RIGHT)) && ((m_size.x > SIZE_X)))){
                return (true);
            };
            return (false);
        }
        protected function convertStretchToAdjacent():void{
            var _local5:int;
            var _local6:Road;
            var _local7:int;
            var _local8:Boolean;
            this.m_isStretchSection = false;
            var _local1:int;
            var _local2 = -1;
            var _local3:int;
            var _local4 = -1;
            for each (_local5 in this.m_adjacentStretch) {
                _local6 = this.m_adjacentRoads[_local5];
                _local7 = Road.m_flipDirection[_local5];
                if (((this.permitStretch(_local5, _local6)) || (_local6.permitStretch(_local7, this)))){
                    _local1++;
                    this.m_stretchDirection = _local5;
                    if (this.m_adjacent.indexOf(_local7) >= 0){
                        _local2 = _local5;
                        _local3++;
                    };
                } else {
                    this.m_adjacentRoads[_local5] = null;
                };
            };
            this.m_isStretchSection = (_local1 == 1);
            if ((((_local1 == 2)) && ((_local3 == 1)))){
                this.m_isStretchSection = true;
                this.m_stretchDirection = _local2;
                for each (_local5 in this.m_adjacentStretch) {
                    if (_local5 != this.m_stretchDirection){
                        this.m_adjacentRoads[_local5] = null;
                    };
                };
            };
            if (this.m_isStretchSection){
                _local8 = false;
                _local5 = this.m_stretchDirection;
                _local6 = this.m_adjacentRoads[_local5];
                switch (_local5){
                    case UP:
                    case DOWN:
                        _local8 = !((_local6.getPosition().x == getPosition().x));
                        break;
                    case LEFT:
                    case RIGHT:
                        _local8 = !((_local6.getPosition().y == getPosition().y));
                        break;
                };
                if (_local8){
                    this.m_adjacentPartial.push(_local5);
                    this.m_adjacentPartial = this.m_adjacentPartial.sort();
                } else {
                    this.m_adjacent.push(_local5);
                    this.m_adjacent = this.m_adjacent.sort();
                };
            };
            if ((this.m_adjacentPartial.length + this.m_adjacent.length) > 2){
                this.m_isCorner = true;
            };
        }
        protected function discardInvalidLinks():void{
            var _local2:int;
            var _local3:Road;
            var _local4:Road;
            var _local1:int;
            while (_local1 < this.m_adjacentPartial.length) {
                _local2 = this.m_adjacentPartial[_local1];
                _local3 = this.m_adjacentRoads[_local2];
                if (_local3 == null){
                } else {
                    _local4 = _local3.m_adjacentRoads[Road.m_flipDirection[_local2]];
                    if (_local4 != this){
                        this.m_adjacentRoads[_local2] = null;
                        this.m_adjacentPartial.splice(_local1, 1);
                        _local1--;
                    };
                };
                _local1++;
            };
            _local1 = 0;
            while (_local1 < this.m_adjacent.length) {
                _local2 = this.m_adjacent[_local1];
                _local3 = this.m_adjacentRoads[_local2];
                if (_local3 == null){
                } else {
                    _local4 = _local3.m_adjacentRoads[Road.m_flipDirection[_local2]];
                    if (_local4 != this){
                        this.m_adjacentRoads[_local2] = null;
                        this.m_adjacent.splice(_local1, 1);
                        _local1--;
                    };
                };
                _local1++;
            };
        }
        public function calculateRoadConnectivity1():void{
            var _local1:Road;
            var _local2:Array;
            var _local3:Array;
            var _local4:int;
            var _local5:Array;
            this.updateAdjacent();
            for each (_local1 in this.m_adjacentRoads) {
                if (((!((_local1 == null))) && ((_local1.m_adjacent == null)))){
                    _local1.updateAdjacent();
                };
            };
            _local2 = this.m_adjacent;
            this.convertTightToAdjacent();
            this.convertStretchToAdjacent();
            _local3 = this.m_adjacent.concat(this.m_adjacentPartial);
            if (_local3.length == 2){
                this.m_isCorner = true;
                if ((((_local3.indexOf(LEFT) >= 0)) && ((_local3.indexOf(RIGHT) >= 0)))){
                    this.m_isCorner = false;
                };
                if ((((_local3.indexOf(UP) >= 0)) && ((_local3.indexOf(DOWN) >= 0)))){
                    this.m_isCorner = false;
                };
            };
            if (((((!(m_allowStretchCorners)) && (this.m_isCorner))) && ((this.m_adjacent.length < 2)))){
                this.m_isCorner = false;
                for each (_local4 in this.m_adjacentPartial) {
                    this.m_adjacentRoads[_local4] = null;
                };
                this.m_adjacentPartial = [];
            };
            if ((((_local3.length == 3)) && ((this.m_adjacent.length > 1)))){
                this.m_isCorner = true;
            };
            if ((((_local3.length == 4)) && ((this.m_adjacent.length > 1)))){
                this.m_isCorner = true;
            };
            this.m_currentRule = null;
            if (this.m_adjacentPartial.length > 0){
                _local5 = this.m_adjacent.concat(this.m_adjacentPartial);
                _local5.sort();
                this.m_currentRule = this.matchPartialRule(_local5);
            };
            if (((((this.m_currentRule) && (!((this.m_adjacentRoads[UP] == null))))) && (!((this.m_adjacentRoads[DOWN] == null))))){
                this.m_isUpDown = true;
            };
            if (((((this.m_currentRule) && (!((this.m_adjacentRoads[LEFT] == null))))) && (!((this.m_adjacentRoads[RIGHT] == null))))){
                this.m_isLeftRight = true;
            };
        }
        public function trimPartials():void{
            var _local2:int;
            var _local3:int;
            var _local4:int;
            var _local5:int;
            var _local6:Road;
            this.convertPartialsToAdjacent();
            var _local1:Array = this.m_adjacent.concat(this.m_adjacentPartial);
            _local1 = _local1.sort();
            this.m_currentRule = this.matchPartialRule(_local1);
            while ((((this.m_currentRule == null)) && ((this.m_adjacentPartial.length > 0)))) {
                _local2 = 10;
                _local3 = -1;
                _local4 = 0;
                while (_local4 < this.m_adjacentPartial.length) {
                    _local5 = 0;
                    _local6 = this.m_adjacentRoads[this.m_adjacentPartial[_local4]];
                    if (_local6.m_position.x == m_position.x){
                        _local5++;
                    };
                    if (_local6.m_position.y == m_position.y){
                        _local5++;
                    };
                    if ((_local6.m_position.x + _local6.m_size.x) == (m_position.x + m_size.x)){
                        _local5++;
                    };
                    if ((_local6.m_position.y + _local6.m_size.y) == (m_position.y + m_size.y)){
                        _local5++;
                    };
                    if (_local5 < _local2){
                        _local2 = _local5;
                        _local3 = _local4;
                    };
                    _local4++;
                };
                this.m_adjacentRoads[this.m_adjacentPartial[_local3]] = null;
                this.m_adjacentPartial.splice(_local3, 1);
                _local1 = this.m_adjacent.concat(this.m_adjacentPartial);
                _local1.sort();
                this.m_currentRule = this.matchPartialRule(_local1);
            };
        }
        public function calculateRoadConnectivity2():void{
            var _local1:Array;
            var _local2:Road;
            var _local3:int;
            if (this.m_isStretchSection){
                _local2 = this.m_adjacentRoads[this.m_stretchDirection];
                if ((((_local2 == null)) || (!(this.shouldStretch(_local2, this.m_stretchDirection))))){
                    this.m_isStretchSection = false;
                };
                if (this.m_adjacentRoads[this.m_stretchDirection] == null){
                    this.m_isStretchSection = false;
                };
            };
            this.m_currentRule = null;
            if (this.m_adjacentPartial.length > 0){
                _local1 = this.m_adjacent.concat(this.m_adjacentPartial);
                _local1.sort();
                this.m_currentRule = this.matchPartialRule(_local1);
                if (this.m_currentRule == null){
                    this.trimPartials();
                };
            };
            if (((this.m_isStretchSection) && ((this.m_adjacentRoads[this.m_stretchDirection] == null)))){
                this.m_isStretchSection = false;
            };
            if (this.m_currentRule != null){
                if (("corner" in this.m_currentRule)){
                    this.m_currentRule = this.checkOverlapCorner();
                };
            };
            if (this.m_currentRule == null){
                for each (_local3 in this.m_adjacentPartial) {
                    this.m_adjacentRoads[_local3] = null;
                };
                this.m_adjacentPartial = [];
                this.m_currentRule = this.matchFullRule(this.m_adjacent);
                if ((((((((this.m_currentRule == null)) && (this.m_isStretchSection))) && ((m_size.x == SIZE_X)))) && ((m_size.y == SIZE_Y)))){
                    this.m_adjacentRoads[this.m_stretchDirection] = null;
                    this.m_adjacent.splice(this.m_adjacent.indexOf(this.m_stretchDirection), 1);
                    this.m_isStretchSection = false;
                    this.m_currentRule = this.matchFullRule(this.m_adjacent);
                };
            };
            if (this.m_currentRule == null){
                this.m_adjacent = [];
                this.m_adjacentRoads = [];
                this.m_adjacentPartial = [];
            };
        }
        public function calculateRoadConnectivity3():void{
            var _local1:String;
            var _local3:int;
            var _local4:Road;
            var _local5:int;
            var _local6:Boolean;
            if (this.m_adjacent == null){
                return;
            };
            this.discardInvalidLinks();
            if (this.m_isTightSection){
                _local4 = this.m_adjacentRoads[this.m_tightDirection];
                if ((((_local4 == null)) || (!(this.shouldTighten(_local4, this.m_tightDirection))))){
                    this.m_isTightSection = false;
                } else {
                    if (this.m_isRoadBeingDragged){
                        if ((this.m_adjacentPartial.length + this.m_adjacent.length) == 1){
                            this.m_isTightSection = false;
                            this.m_adjacentPartial = [];
                            this.m_adjacent = [];
                            this.m_adjacentRoads = [];
                        };
                    };
                };
            };
            if (this.m_isStretchSection){
                _local4 = this.m_adjacentRoads[this.m_stretchDirection];
                if ((((_local4 == null)) || (!(this.shouldStretch(_local4, this.m_stretchDirection))))){
                    this.m_isStretchSection = false;
                };
            };
            var _local2:int;
            for each (_local4 in this.m_adjacentRoads) {
                if (_local4 != null){
                    _local2++;
                };
            };
            if (_local2 < 2){
                this.m_isCorner = false;
            };
            for each (_local3 in this.m_adjacentPartial) {
                _local5 = Road.m_flipDirection[_local3];
                _local4 = (this.m_adjacentRoads[_local3] as Road);
                _local6 = ((!((_local4 == null))) && ((_local4.m_adjacentPartial.indexOf(_local5) >= 0)));
                if (((_local4) && (!(_local6)))){
                    if (this.m_isCorner){
                        _local6 = true;
                    };
                };
                if (!_local6){
                    this.m_adjacentPartial.splice(this.m_adjacentPartial.indexOf(_local3), 1);
                    this.m_adjacentRoads[_local3] = null;
                };
            };
            this.m_didConnectivity = true;
        }
        public function calculateRoadImage():void{
            var _local1:Array;
            this.discardInvalidLinks();
            this.m_currentRule = null;
            var _local2:Array = this.m_adjacent;
            if (Road.s_shrinkRoad1 == this){
                if (_local2.indexOf(s_shrinkDir1) < 0){
                    _local2 = _local2.concat(Road.s_shrinkDir1);
                    _local2.sort();
                };
            } else {
                if (Road.s_shrinkRoad2 == this){
                    if (_local2.indexOf(s_shrinkDir2) < 0){
                        _local2 = _local2.concat(s_shrinkDir2);
                        _local2.sort();
                    };
                } else {
                    if (((((this.m_isRoadBeingDragged) && (!((s_shrinkRoad1 == null))))) && (!((s_shrinkRoad2 == null))))){
                        if (_local2.indexOf(s_shrinkDir1) < 0){
                            _local2 = _local2.concat(s_shrinkDir1);
                        };
                        if (_local2.indexOf(s_shrinkDir2) < 0){
                            _local2 = _local2.concat(s_shrinkDir2);
                        };
                        _local2.sort();
                    };
                };
            };
            if (this.m_adjacentPartial.length > 0){
                _local1 = _local2.concat(this.m_adjacentPartial);
                _local1.sort();
                this.m_currentRule = this.matchPartialRule(_local1);
            };
            if (this.m_currentRule != null){
                if (("corner" in this.m_currentRule)){
                    this.m_currentRule = this.checkOverlapCorner();
                };
            };
            if (this.m_currentRule == null){
                this.m_currentRule = this.matchFullRule(_local2);
            };
            if (this.m_currentRule == null){
                this.m_adjacent = [];
                this.m_adjacentRoads = [];
                this.m_adjacentPartial = [];
                this.m_currentRule = this.matchFullRule(this.m_adjacent);
            };
            this.calculateOverlayOffsets();
            var _local3:int = m_depthIndex;
            this.calculateDepthIndex();
            if (_local3 != this.m_depthIndex){
                this.conditionallyReattach(true);
            };
        }
        public function isRoadTile(_arg1:int, _arg2:int, _arg3:int):Road{
            var _local8:Road;
            var _local9:Vector3;
            var _local4:Road;
            if ((((_arg3 == UP)) && ((m_size.y > SIZE_Y)))){
                _arg2 = (_arg2 + 1);
            };
            if ((((_arg3 == RIGHT)) && ((m_size.x > SIZE_X)))){
                _arg1 = (_arg1 + 1);
            };
            var _local5:Array = Global.world.getCollisionMap().getObjectsByPosition(_arg1, _arg2);
            var _local6:Vector3 = new Vector3(_arg1, _arg2);
            var _local7:int;
            while (_local7 < _local5.length) {
                _local8 = (_local5[_local7] as Road);
                if (_local8){
                    _local9 = _local8.getPosition();
                    if ((((_arg3 == LEFT)) && ((_local8.m_size.x > SIZE_X)))){
                        _local9.x = (_local9.x + 1);
                    };
                    if ((((_arg3 == DOWN)) && ((_local8.m_size.y > SIZE_Y)))){
                        _local9.y = (_local9.y + 1);
                    };
                    if (_local9.equals(_local6)){
                        _local4 = _local8;
                        break;
                    };
                };
                _local7++;
            };
            if (_local4 != null){
                if (_local4.m_invalidDragPos){
                    return (null);
                };
                if ((((((_arg3 == UP)) || ((_arg3 == DOWN)))) && (((!((m_size.x == SIZE_X))) || (!((_local4.m_size.x == SIZE_X))))))){
                    return (null);
                };
                if ((((((_arg3 == LEFT)) || ((_arg3 == RIGHT)))) && (((!((m_size.y == SIZE_Y))) || (!((_local4.m_size.y == SIZE_Y))))))){
                    return (null);
                };
            };
            if (((!((_local4 == null))) && (_local4.m_invalidDragPos))){
                return (null);
            };
            return (_local4);
        }
        public function isPartialMatchRoadTile(_arg1:int, _arg2:int, _arg3:int, _arg4:int, _arg5:int):Road{
            var _local8:Road;
            var _local9:Vector3;
            var _local6:Array = Global.world.getCollisionMap().getObjectsByPosition(_arg3, _arg4);
            _local6 = _local6.concat(Global.world.getCollisionMap().getObjectsByPosition((_arg3 + 1), _arg4));
            _local6 = _local6.concat(Global.world.getCollisionMap().getObjectsByPosition(_arg3, (_arg4 + 1)));
            var _local7:int;
            while (_local7 < _local6.length) {
                _local8 = (_local6[_local7] as Road);
                if (_local8){
                    if (_local8.m_invalidDragPos){
                    } else {
                        if ((((_arg5 == DOWN)) && ((_local8.m_size.y < SIZE_Y)))){
                        } else {
                            if ((((_arg5 == LEFT)) && ((_local8.m_size.x < SIZE_X)))){
                            } else {
                                if ((((_arg5 == UP)) && ((m_size.y < SIZE_Y)))){
                                } else {
                                    if ((((_arg5 == RIGHT)) && ((m_size.x < SIZE_X)))){
                                    } else {
                                        _local9 = _local8.getPosition();
                                        if ((((((((_arg5 == LEFT)) || ((_arg5 == RIGHT)))) && ((_local8.m_size.y < SIZE_Y)))) && ((_local9.y < _arg2)))){
                                        } else {
                                            if ((((((((_arg5 == UP)) || ((_arg5 == DOWN)))) && ((_local8.m_size.x < SIZE_X)))) && ((_local9.x < _arg1)))){
                                            } else {
                                                if ((((_arg1 == _arg3)) && ((_arg4 == _local9.y)))){
                                                    if (Math.abs((_arg1 - _local9.x)) < 1.01){
                                                        return (_local8);
                                                    };
                                                };
                                                if ((((_arg2 == _arg4)) && ((_arg3 == _local9.x)))){
                                                    if (Math.abs((_arg2 - _local9.y)) < 1.01){
                                                        return (_local8);
                                                    };
                                                };
                                            };
                                        };
                                    };
                                };
                            };
                        };
                    };
                };
                _local7++;
            };
            return (null);
        }
        public function isTightMatchRoadTile(_arg1:int, _arg2:int, _arg3:int, _arg4:int, _arg5:int):Road{
            var _local8:Road;
            var _local9:Vector3;
            var _local6:Array = Global.world.getCollisionMap().getObjectsByPosition(_arg3, _arg4);
            _local6 = _local6.concat(Global.world.getCollisionMap().getObjectsByPosition((_arg3 + 1), _arg4));
            _local6 = _local6.concat(Global.world.getCollisionMap().getObjectsByPosition(_arg3, (_arg4 + 1)));
            var _local7:int;
            while (_local7 < _local6.length) {
                _local8 = (_local6[_local7] as Road);
                if (_local8){
                    if (_local8.m_invalidDragPos){
                    } else {
                        _local9 = _local8.getPosition();
                        if ((((_arg1 == _arg3)) && ((_arg4 == _local9.y)))){
                            if (Math.abs((_arg1 - _local9.x)) < 1.01){
                                return (_local8);
                            };
                        };
                        if ((((_arg2 == _arg4)) && ((_arg3 == _local9.x)))){
                            if (Math.abs((_arg2 - _local9.y)) < 1.01){
                                return (_local8);
                            };
                        };
                    };
                };
                _local7++;
            };
            return (null);
        }
        public function isStretchMatchRoadTile(_arg1:int, _arg2:int, _arg3:int, _arg4:int, _arg5:int):Road{
            var _local8:Road;
            var _local9:Vector3;
            var _local6:Array = Global.world.getCollisionMap().getObjectsByPosition(_arg3, _arg4);
            _local6 = _local6.concat(Global.world.getCollisionMap().getObjectsByPosition((_arg3 + 1), _arg4));
            _local6 = _local6.concat(Global.world.getCollisionMap().getObjectsByPosition(_arg3, (_arg4 + 1)));
            var _local7:int;
            while (_local7 < _local6.length) {
                _local8 = (_local6[_local7] as Road);
                if (_local8){
                    if (_local8.m_invalidDragPos){
                    } else {
                        _local9 = _local8.getPosition();
                        if ((((_arg1 == _arg3)) && ((_arg4 == _local9.y)))){
                            if (Math.abs((_arg1 - _local9.x)) < 1.01){
                                return (_local8);
                            };
                        };
                        if ((((_arg2 == _arg4)) && ((_arg3 == _local9.x)))){
                            if (Math.abs((_arg2 - _local9.y)) < 1.01){
                                return (_local8);
                            };
                        };
                    };
                };
                _local7++;
            };
            return (null);
        }
        override public function attach():void{
            this.m_attached = true;
            super.attach();
        }
        override public function detach():void{
            super.detach();
            this.m_attached = false;
            this.clearContent();
            this.clearAdjacent();
        }
        override public function getSnapX():int{
            return (1);
        }
        override public function getSnapY():int{
            return (1);
        }
        override public function onSell():void{
            super.onSell();
            Global.world.citySim.roadManager.updateAllRoadTiles();
        }
        override public function preDisableMove(_arg1:String, _arg2:int):void{
            var _local4:Road;
            if (this.m_saveDragItem != null){
                setItem(this.m_saveDragItem);
                this.m_saveDragItem = null;
            };
            var _local3:Array = Global.world.getObjectsByClass(Road);
            for each (_local4 in _local3) {
                if (_local4 != null){
                    if (_local4.m_saveDragItem != null){
                        _local4.setItem(_local4.m_saveDragItem);
                        _local4.m_saveDragItem = null;
                    };
                };
                _local4.m_checkForReplaceAtDrop = false;
            };
            this.m_isRoadBeingDragged = false;
        }
        override public function postDisableMove(_arg1:Vector3):void{
            this.m_isRoadBeingDragged = false;
            Global.world.citySim.roadManager.updateAllRoadTiles();
        }
        public function baseRoadName():String{
            var _local1:String = m_item.name;
            if (_local1.search("-") > 0){
                _local1 = _local1.slice(0, _local1.search("-"));
                return (_local1);
            };
            return (_local1);
        }
        protected function shrinkTile(_arg1:Road, _arg2:int):void{
            var _local3:Item = Global.gameSettings.getItemByName((this.baseRoadName() + "-2"));
            if (_local3 != null){
                _arg1.setItem(_local3);
                _arg1.setDirection(_arg2);
                _arg1.updateSize();
                _arg1.conditionallyReattach(true);
                if (_arg1.m_id != 0){
                    GameTransactionManager.addTransaction(new TReplace(_arg1, _arg1));
                };
                setItem(_local3);
                setDirection(_arg2);
                updateSize();
                if (_arg2){
                    m_position.y = (_arg1.m_position.y + 2);
                } else {
                    m_position.x = (_arg1.m_position.x + 2);
                };
                conditionallyReattach(true);
                this.m_saveDragItem = null;
                if (this.m_id != 0){
                    GameTransactionManager.addTransaction(new TReplace(this, this));
                };
            };
        }
        protected function shrinkOneTile(_arg1:Boolean):Boolean{
            var _local7:Object;
            var _local8:Road;
            var _local9:Road;
            var _local10:int;
            var _local11:Road;
            var _local12:int;
            var _local13:Vector3;
            var _local14:Vector3;
            var _local15:Road;
            var _local16:Boolean;
            var _local17:Boolean;
            var _local18:Boolean;
            var _local19:Boolean;
            var _local20:Vector3;
            var _local2:Vector3 = getPosition();
            var _local3:Vector3 = getSize();
            var _local4:Array = [];
            s_shrinkRoad1 = null;
            s_shrinkRoad2 = null;
            s_shrinkDir1 = -1;
            s_shrinkDir2 = -1;
            var _local5:Array = [];
            var _local6:Array = [];
            Global.world.checkCollision((_local2.x - 1), _local2.y, ((_local2.x + _local3.x) + 1), (_local2.y + _local3.y), [this], _local5, Constants.WORLDOBJECT_ALL, this);
            for each (_local7 in _local5) {
                if (((!((_local7 is Road))) || ((_local7 is ParkingLot)))){
                    _local5 = [];
                    break;
                };
            };
            Global.world.checkCollision(_local2.x, (_local2.y - 1), (_local2.x + _local3.x), ((_local2.y + _local3.y) + 1), [this], _local6, Constants.WORLDOBJECT_ALL, this);
            for each (_local7 in _local6) {
                if (((!((_local7 is Road))) || ((_local7 is ParkingLot)))){
                    _local6 = [];
                    break;
                };
            };
            if (_local5.length == 2){
                _local4 = _local5;
            } else {
                if (_local6.length == 2){
                    _local4 = _local6;
                } else {
                    if (_local5.length == 3){
                        _local4 = _local5;
                    } else {
                        _local4 = _local6;
                    };
                };
            };
            if (_local4.length > 1){
                if (_local4.length == 2){
                    _local8 = _local4[0];
                    _local9 = _local4[1];
                    if ((((_local8.m_size.x < SIZE_X)) || ((_local8.m_size.y < SIZE_Y)))){
                        return (false);
                    };
                    _local10 = 0;
                    _local11 = null;
                    for each (_local11 in _local8.adjacentRoads) {
                        if (((!((_local11 == null))) && (!((_local11 == this))))){
                            _local10++;
                        };
                    };
                    _local12 = 0;
                    for each (_local11 in _local9.adjacentRoads) {
                        if (((!((_local11 == null))) && (!((_local11 == this))))){
                            _local12++;
                        };
                    };
                    if ((((_local10 > 1)) && ((_local12 > 1)))){
                        return (false);
                    };
                    _local13 = _local8.getPosition();
                    _local14 = _local9.getPosition();
                    if ((((_local13.x == _local14.x)) && ((_local13.x == _local2.x)))){
                        if (((_local13.y + _local8.getSize().y) + 1) == _local14.y){
                            if (_arg1){
                                this.shrinkTile(_local8, 1);
                                return (true);
                            };
                            s_shrinkRoad1 = _local8;
                            s_shrinkDir1 = UP;
                            s_shrinkRoad2 = _local9;
                            s_shrinkDir2 = DOWN;
                            return (true);
                        };
                        if (((_local14.y + _local9.getSize().y) + 1) == _local13.y){
                            if (_arg1){
                                this.shrinkTile(_local9, 1);
                                return (true);
                            };
                            s_shrinkRoad1 = _local9;
                            s_shrinkDir1 = UP;
                            s_shrinkRoad2 = _local8;
                            s_shrinkDir2 = DOWN;
                            return (true);
                        };
                    } else {
                        if ((((_local13.y == _local14.y)) && ((_local13.y == _local2.y)))){
                            if (((_local13.x + _local8.getSize().x) + 1) == _local14.x){
                                if (_arg1){
                                    this.shrinkTile(_local8, 0);
                                    return (true);
                                };
                                s_shrinkRoad1 = _local8;
                                s_shrinkDir1 = RIGHT;
                                s_shrinkRoad2 = _local9;
                                s_shrinkDir2 = LEFT;
                                return (true);
                            };
                            if (((_local14.x + _local9.getSize().x) + 1) == _local13.x){
                                if (_arg1){
                                    this.shrinkTile(_local9, 0);
                                    return (true);
                                };
                                s_shrinkRoad1 = _local9;
                                s_shrinkDir1 = RIGHT;
                                s_shrinkRoad2 = _local8;
                                s_shrinkDir2 = LEFT;
                                return (true);
                            };
                        };
                    };
                } else {
                    if (_local4.length == 3){
                        for each (_local11 in _local4) {
                            _local20 = _local11.getPosition();
                            if (_local11.m_position.x == m_position.x){
                                if (_local8 != null){
                                    return (false);
                                };
                                _local8 = _local11;
                            } else {
                                if (_local11.m_position.y == m_position.y){
                                    if (_local8 != null){
                                        return (false);
                                    };
                                    _local8 = _local11;
                                } else {
                                    if (_local9 == null){
                                        _local9 = _local11;
                                    } else {
                                        if (_local15 == null){
                                            _local15 = _local11;
                                        } else {
                                            return (false);
                                        };
                                    };
                                };
                            };
                        };
                        if ((((((_local8 == null)) || ((_local9 == null)))) || ((_local15 == null)))){
                            return (false);
                        };
                        if ((((_local8.m_size.x < SIZE_X)) || ((_local8.m_size.y < SIZE_Y)))){
                            return (false);
                        };
                        _local10 = 0;
                        for each (_local11 in _local8.adjacentRoads) {
                            if (((!((_local11 == null))) && (!((_local11 == this))))){
                                _local10++;
                            };
                        };
                        if (_local10 > 1){
                            return (false);
                        };
                        _local16 = (m_position.x == _local8.m_position.x);
                        _local17 = (m_position.y == _local8.m_position.y);
                        _local18 = (_local9.m_position.x == _local15.m_position.x);
                        _local19 = (_local9.m_position.y == _local15.m_position.y);
                        if (((_local16) && (_local19))){
                            if (((_local8.m_position.y + _local8.m_size.y) + 1) == _local9.m_position.y){
                                if (_arg1){
                                    this.shrinkTile(_local8, 1);
                                    return (true);
                                };
                                s_shrinkRoad1 = _local8;
                                s_shrinkDir1 = UP;
                                s_shrinkRoad2 = _local9;
                                s_shrinkDir2 = DOWN;
                                return (true);
                            };
                            if (_local8.m_position.y == ((_local9.m_position.y + _local9.m_size.y) + 1)){
                                if (_arg1){
                                    _local8.m_position.y = (_local8.m_position.y - 1);
                                    this.shrinkTile(_local8, 1);
                                    return (true);
                                };
                                s_shrinkRoad1 = _local8;
                                s_shrinkDir1 = DOWN;
                                s_shrinkRoad2 = _local9;
                                s_shrinkDir2 = UP;
                                return (true);
                            };
                        } else {
                            if (((_local17) && (_local18))){
                                if (((_local8.m_position.x + _local8.m_size.x) + 1) == _local9.m_position.x){
                                    if (_arg1){
                                        this.shrinkTile(_local8, 0);
                                        return (true);
                                    };
                                    s_shrinkRoad1 = _local8;
                                    s_shrinkDir1 = RIGHT;
                                    s_shrinkRoad2 = _local9;
                                    s_shrinkDir2 = LEFT;
                                    return (true);
                                };
                                if (_local8.m_position.x == ((_local9.m_position.x + _local9.m_size.x) + 1)){
                                    if (_arg1){
                                        _local8.m_position.x = (_local8.m_position.x - 1);
                                        this.shrinkTile(_local8, 0);
                                        return (true);
                                    };
                                    s_shrinkRoad1 = _local8;
                                    s_shrinkDir1 = LEFT;
                                    s_shrinkRoad2 = _local9;
                                    s_shrinkDir2 = RIGHT;
                                    return (true);
                                };
                            };
                        };
                    };
                };
            };
            return (false);
        }
        protected function stretchTile(_arg1:int):void{
            var _local2:Item = Global.gameSettings.getItemByName((this.baseRoadName() + "-4"));
            if (_local2 != null){
                this.setItem(_local2);
                this.setDirection(_arg1);
                this.updateSize();
                this.conditionallyReattach(true);
                if (m_id != 0){
                    GameTransactionManager.addTransaction(new TReplace(this, this));
                };
            };
        }
        protected function stretchOneTile(_arg1:Boolean):Boolean{
            var _local5:Object;
            var _local6:Road;
            var _local7:Road;
            var _local8:Vector3;
            var _local9:Vector3;
            var _local10:Vector3;
            var _local11:Vector3;
            var _local12:Road;
            var _local13:Road;
            var _local14:Boolean;
            var _local15:Boolean;
            var _local16:Boolean;
            var _local17:Boolean;
            var _local18:Vector3;
            var _local2:Vector3 = getPosition();
            var _local3:Vector3 = getSize();
            var _local4:Array = [];
            if (Global.world.checkCollision((_local2.x - 1), (_local2.y - 1), ((_local2.x + _local3.x) + 2), ((_local2.y + _local3.y) + 2), [this], _local4, Constants.WORLDOBJECT_ALL, this)){
                for each (_local5 in _local4) {
                    if (!(_local5 is Road)){
                        return (false);
                    };
                };
                if (_local4.length == 2){
                    _local6 = _local4[0];
                    _local7 = _local4[1];
                    _local8 = _local6.getPosition();
                    _local9 = _local7.getPosition();
                    _local10 = _local6.getSize();
                    _local11 = _local7.getSize();
                    if ((((_local8.x == _local9.x)) && ((_local8.x == _local2.x)))){
                        if (((_local8.y + _local6.getSize().y) + 1) == _local9.y){
                            if (_arg1){
                                _local6.stretchTile(1);
                            };
                            return (true);
                        };
                        if (((_local9.y + _local7.getSize().y) + 1) == _local8.y){
                            if (_arg1){
                                _local7.stretchTile(1);
                            };
                            return (true);
                        };
                    } else {
                        if ((((_local8.y == _local9.y)) && ((_local8.y == _local2.y)))){
                            if (((_local8.x + _local6.getSize().x) + 1) == _local9.x){
                                if (_arg1){
                                    _local6.stretchTile(0);
                                };
                                return (true);
                            };
                            if (((_local9.x + _local7.getSize().x) + 1) == _local8.x){
                                if (_arg1){
                                    _local7.stretchTile(0);
                                };
                                return (true);
                            };
                        };
                    };
                } else {
                    if (_local4.length == 3){
                        for each (_local13 in _local4) {
                            _local18 = _local13.getPosition();
                            if (_local13.m_position.x == m_position.x){
                                if (_local6 != null){
                                    return (false);
                                };
                                _local6 = _local13;
                            } else {
                                if (_local13.m_position.y == m_position.y){
                                    if (_local6 != null){
                                        return (false);
                                    };
                                    _local6 = _local13;
                                } else {
                                    if (_local7 == null){
                                        _local7 = _local13;
                                    } else {
                                        if (_local12 == null){
                                            _local12 = _local13;
                                        } else {
                                            return (false);
                                        };
                                    };
                                };
                            };
                        };
                        if ((((((_local6 == null)) || ((_local7 == null)))) || ((_local12 == null)))){
                            return (false);
                        };
                        _local14 = (m_position.x == _local6.m_position.x);
                        _local15 = (m_position.y == _local6.m_position.y);
                        _local16 = (_local7.m_position.x == _local12.m_position.x);
                        _local17 = (_local7.m_position.y == _local12.m_position.y);
                        if (((_local14) && (_local17))){
                            if (((_local6.m_position.y + _local6.m_size.y) + 1) == _local7.m_position.y){
                                if (_arg1){
                                    _local6.stretchTile(1);
                                };
                                return (true);
                            };
                            if (_local6.m_position.y == ((_local7.m_position.y + _local7.m_size.y) + 1)){
                                if (_arg1){
                                    _local6.m_position.y = (_local6.m_position.y - 1);
                                    _local6.stretchTile(1);
                                };
                                return (true);
                            };
                        } else {
                            if (((_local15) && (_local16))){
                                if (((_local6.m_position.x + _local6.m_size.x) + 1) == _local7.m_position.x){
                                    if (_arg1){
                                        _local6.stretchTile(0);
                                    };
                                    return (true);
                                };
                                if (_local6.m_position.x == ((_local7.m_position.x + _local7.m_size.x) + 1)){
                                    if (_arg1){
                                        _local6.m_position.x = (_local6.m_position.x - 1);
                                        _local6.stretchTile(0);
                                    };
                                    return (true);
                                };
                            };
                        };
                    };
                };
            };
            return (false);
        }
        public function isPositionValid():Boolean{
            if (this.shrinkOneTile(false)){
                return (true);
            };
            var _local1:Vector3 = getPosition();
            var _local2:Vector3 = getSize();
            if (this.m_isTightSection){
                switch (this.m_tightDirection){
                    case LEFT:
                        _local1.x = (_local1.x + 1);
                        _local2.x = (_local2.x - 1);
                        break;
                    case RIGHT:
                        _local2.x = (_local2.x - 1);
                        break;
                    case DOWN:
                        _local1.y = (_local1.y + 1);
                        _local2.y = (_local2.y - 1);
                        break;
                    case UP:
                        _local2.y = (_local2.y - 1);
                        break;
                };
            };
            if (Global.world.checkCollision(_local1.x, _local1.y, (_local1.x + _local2.x), (_local1.y + _local2.y), [this], null, Constants.WORLDOBJECT_ALL, this)){
                return (false);
            };
            return (true);
        }
        override public function onObjectDrag(_arg1:Vector3):void{
            var _local2:Array;
            var _local3:Road;
            this.m_isRoadBeingDragged = true;
            if ((((this.m_saveDragItem == null)) && (!((this.m_adjacentRoads == null))))){
                _local2 = this.m_adjacentRoads.concat(this);
                for each (_local3 in _local2) {
                    canSwitchToBaseItem(_local3);
                };
            };
            if (this.m_saveDragItem == null){
                this.m_saveDragItem = this.m_item;
            };
            super.onObjectDrag(_arg1);
            s_nearX = m_position.x;
            s_nearY = m_position.y;
            _local2 = Global.world.getObjectsByPredicate(nearbyRoads);
            Global.world.citySim.roadManager.updateRoadTiles(_local2);
            if (!this.isPositionValid()){
                this.m_invalidDragPos = true;
                Global.world.citySim.roadManager.updateRoadTiles(_local2);
                this.m_invalidDragPos = false;
            };
            conditionallyReattach(true);
        }
        protected function checkForNewCorner(_arg1:Vector2):Road{
            var _local2:Boolean;
            var _local3:Road;
            this.clearContent();
            if (this.m_adjacentPartial.length == 1){
                _local2 = false;
                if (this.m_fitShrink){
                    if (this.m_fitOffset.x == 1){
                        _arg1.x = (_arg1.x + 1);
                    } else {
                        if (this.m_fitOffset.x == -1){
                        } else {
                            if (this.m_fitOffset.y == 1){
                                _arg1.y = (_arg1.y + 1);
                                _local2 = true;
                            } else {
                                if (this.m_fitOffset.y == -1){
                                    _local2 = true;
                                } else {
                                    return (null);
                                };
                            };
                        };
                    };
                    _local3 = new Road((this.baseRoadName() + "-2"));
                    _local3.setPosition(_arg1.x, _arg1.y);
                    if (_local2){
                        _local3.rotate();
                    };
                    return (_local3);
                };
                if (this.m_fitStretch){
                    if (this.m_fitOffset.x == 1){
                    } else {
                        if (this.m_fitOffset.x == -1){
                            _arg1.x = (_arg1.x - 1);
                        } else {
                            if (this.m_fitOffset.y == 1){
                                _local2 = true;
                            } else {
                                if (this.m_fitOffset.y == -1){
                                    _arg1.y = (_arg1.y - 1);
                                    _local2 = true;
                                } else {
                                    return (null);
                                };
                            };
                        };
                    };
                    _local3 = new Road((this.baseRoadName() + "-4"));
                    _local3.setPosition(_arg1.x, _arg1.y);
                    if (_local2){
                        _local3.rotate();
                    };
                    return (_local3);
                };
            };
            return (null);
        }
        protected function checkForNewTee(_arg1:Vector2):Road{
            var _local2:Boolean;
            var _local3:Road;
            this.clearContent();
            if (this.m_adjacentPartial.length == 2){
                _local2 = false;
                if (this.m_fitShrink){
                    if (this.m_fitOffset.x == 1){
                        _arg1.x = (_arg1.x + 1);
                    } else {
                        if (this.m_fitOffset.x == -1){
                        } else {
                            if (this.m_fitOffset.y == 1){
                                _arg1.y = (_arg1.y + 1);
                                _local2 = true;
                            } else {
                                if (this.m_fitOffset.y == -1){
                                    _local2 = true;
                                } else {
                                    return (null);
                                };
                            };
                        };
                    };
                    _local3 = new Road((this.baseRoadName() + "-2"));
                    _local3.setPosition(_arg1.x, _arg1.y);
                    if (_local2){
                        _local3.rotate();
                    };
                    return (_local3);
                };
                if (this.m_fitStretch){
                    if (this.m_fitOffset.x == 1){
                    } else {
                        if (this.m_fitOffset.x == -1){
                            _arg1.x = (_arg1.x - 1);
                        } else {
                            if (this.m_fitOffset.y == 1){
                                _local2 = true;
                            } else {
                                if (this.m_fitOffset.y == -1){
                                    _arg1.y = (_arg1.y - 1);
                                    _local2 = true;
                                } else {
                                    return (null);
                                };
                            };
                        };
                    };
                    _local3 = new Road((this.baseRoadName() + "-4"));
                    _local3.setPosition(_arg1.x, _arg1.y);
                    if (_local2){
                        _local3.rotate();
                    };
                    return (_local3);
                };
            };
            return (null);
        }
        protected function shouldReplaceRoad(_arg1:Vector2):Road{
            var _local5:Boolean;
            var _local2:Road;
            if (this.m_isTightSection){
                _local5 = false;
                switch (this.m_tightDirection){
                    case LEFT:
                        _arg1.x = (_arg1.x + 1);
                        break;
                    case DOWN:
                        _arg1.y = (_arg1.y + 1);
                        _local5 = true;
                        break;
                    case UP:
                        _local5 = true;
                        break;
                };
                _local2 = new Road((this.baseRoadName() + "-2"));
                _local2.setPosition(_arg1.x, _arg1.y);
                if (_local5){
                    _local2.rotate();
                };
            } else {
                if (((!((this.m_currentRule == null))) && (("corner" in this.m_currentRule)))){
                    _local2 = this.checkForNewCorner(_arg1);
                } else {
                    if (((!((this.m_currentRule == null))) && (("tee" in this.m_currentRule)))){
                        _local2 = this.checkForNewTee(_arg1);
                    };
                };
            };
            if (((((((_local2) && (_local2.m_position.equals(m_position)))) && ((_local2.m_item == m_item)))) && (_local2.m_size.equals(m_size)))){
                _local2 = null;
            };
            if (((((!((this.m_saveDragItem == null))) && ((_local2 == null)))) && (!((m_item == this.m_saveDragItem))))){
                _local2 = new Road(this.baseRoadName());
                _local2.setPosition(_arg1.x, _arg1.y);
            };
            this.m_saveDragItem = null;
            this.m_checkForReplaceAtDrop = false;
            if (_local2 == null){
                return (null);
            };
            var _local3:Vector3 = _local2.getSize();
            var _local4:Array = [];
            if (!Global.world.checkCollision(_arg1.x, _arg1.y, (_arg1.x + _local3.x), (_arg1.y + _local3.y), [this], _local4, Constants.WORLDOBJECT_ALL, _local2)){
                _local2.setOuter(Global.world);
                this.m_overlayContentMode = OVERLAY_NONE;
                this.m_overlay1Mode = OVERLAY_NONE;
                this.m_overlay2Mode = OVERLAY_NONE;
                if (this.m_id != 0){
                    GameTransactionManager.addTransaction(new TReplace(this, _local2));
                };
                _local2.m_adjacent = this.m_adjacent;
                _local2.m_adjacentRoads = this.m_adjacentRoads;
                _local2.m_adjacentPartial = this.m_adjacentPartial;
                _local2.m_adjacentTight = this.m_adjacentTight;
                this.detach();
                cleanUp();
                return (_local2);
            };
            return (null);
        }
        public function prepareToDrop(_arg1:Vector3, _arg2:Vector2):Road{
            m_position.x = _arg2.x;
            m_position.y = _arg2.y;
            this.clearContent();
            if (this.shrinkOneTile(true)){
                _arg2.x = m_position.x;
                _arg2.y = m_position.y;
            } else {
                if (this.stretchOneTile(true)){
                    this.detach();
                    if (this.getId()){
                        GameTransactionManager.addTransaction(new TSell(this));
                    };
                    Global.world.citySim.roadManager.updateAllRoadTiles();
                    return (null);
                };
            };
            var _local3:Road = this.shouldReplaceRoad(_arg2);
            if (_local3 != null){
                return (_local3);
            };
            return (this);
        }
        override public function onObjectDrop(_arg1:Vector3):void{
            var _local3:Road;
            var _local5:Road;
            var _local6:Vector2;
            var _local7:Road;
            var _local2:Array = Global.world.getObjectsByClass(Road);
            var _local4:Array = this.m_adjacentRoads;
            for each (_local3 in _local2) {
                if (((!((_local3 == null))) && (_local3.m_checkForReplaceAtDrop))){
                    _local4 = _local4.concat(_local3);
                };
            };
            for each (_local5 in _local4) {
                if (_local5 != null){
                    _local6 = new Vector2(_local5.m_position.x, _local5.m_position.y);
                    _local7 = _local5.shouldReplaceRoad(_local6);
                    _local5.m_checkForReplaceAtDrop = false;
                    if (_local7 != null){
                        _local7.attach();
                    };
                };
            };
            Global.world.citySim.roadManager.updateAllRoadTiles();
            super.onObjectDrop(_arg1);
            this.m_isRoadBeingDragged = false;
        }
        override public function getToolTipHeader():String{
            return (null);
        }
        override public function getGameModeToolTipAction():String{
            var _local1:String = super.getGameModeToolTipAction();
            var _local2:GameMode = Global.world.getTopGameMode();
            if ((_local2 is GMEditRotate)){
                _local1 = null;
            };
            return (_local1);
        }
        override public function isPlacedObjectNonBuilding():Boolean{
            return (true);
        }
        override public function getHotspot():Vector3{
            return (new Vector3((m_position.x + (m_size.x / 2)), (m_position.y + (m_size.y / 2))));
        }

    }
}//package Classes 
